【发布时间】:2021-06-24 00:24:27
【问题描述】:
我是 MongodB 和 nodejs 的新手 GET 工作正常(获取空数组),当我在邮递员中尝试 POST 以获取“类别”时,我收到了这个错误消息
expressjs的分类路由 https://codeshare.io/YLdm0Y
app.js https://codeshare.io/QnWK0x
控制台错误消息
MongoDB connected successfully
(node:6668) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'name' of undefined
at C:\Users\MASTER\Desktop\express\routes\categories.js:16:20
at Layer.handle [as handle_request] (C:\Users\MASTER\Desktop\express\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\MASTER\Desktop\express\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\MASTER\Desktop\express\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\MASTER\Desktop\express\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\MASTER\Desktop\express\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Users\MASTER\Desktop\express\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\MASTER\Desktop\express\node_modules\express\lib\router\index.js:275:10)
at Function.handle (C:\Users\MASTER\Desktop\express\node_modules\express\lib\router\index.js:174:3)
at router (C:\Users\MASTER\Desktop\express\node_modules\express\lib\router\index.js:47:12)
at Layer.handle [as handle_request] (C:\Users\MASTER\Desktop\express\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (C:\Users\MASTER\Desktop\express\node_modules\express\lib\router\index.js:317:13)
at C:\Users\MASTER\Desktop\express\node_modules\express\lib\router\index.js:284:7
at Function.process_params (C:\Users\MASTER\Desktop\express\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\MASTER\Desktop\express\node_modules\express\lib\router\index.js:275:10)
at cors (C:\Users\MASTER\Desktop\express\node_modules\cors\lib\index.js:188:7)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:6668) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:6668) [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.
【问题讨论】:
标签: javascript node.js express