1. There is a problem
(node:2171) UnhandledPromiseRejectionWarning: TypeError: Assignment to
constant variable. at getList
(/Users/dr/Desktop/Project/nodeBlog/src/controller/blog.js:10:9) at
handleBlogRouter (/Users/dr/Desktop/Project/nodeBlog/src/router/blog.js:18:30)
at getPostData.then.postData (/Users/dr/Desktop/Project/nodeBlog/app.js:56:28)
at process._tickCallback (internal/process/next_tick.js:68:7) (node:2171)
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error
originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch().
(rejection id: 1) (node:2171) [DEP0018] DeprecationWarning: Unhandled promise
rejections are deprecated. In the future, promise rejections that are not
handled will terminate the Node.js process with a non-zero exit code.
2. problem analysis

(1) Source code
const blogResult = handleBlogRouter(req, res); if(blogResult){
blogResult.then(blogData => { res.end( JSON.stringify(blogData) ) }) return }
(2) reason

const blogResult = handleBlogRouter(req, res)
A variable is defined and has an initial value , and const The value of will vary with the incoming parameters , So there was a mistake :TypeError: Assignment to constant
variable.

3. resolvent

take const Change to let

4. const And let A comparison of

(1) difference :

*         const It's usually a declaration constant
          as const a=1,const Declared variables must not change values , That means ,const Once the variable is declared , It must be initialized immediately , It can't be assigned later . as const
a This will report an error

*        let Declared variables can be changed , Values and types can be changed , There are no restrictions .
*        const The definition variable must be assigned an initial value ,let There is no need to assign an initial value
(2) common ground :

* let And const All are valid only in the block level scope of the declaration .
 

 

 

Technology