日常记录,nodejs写后台时报错next is not a function

本文记录了一次在使用Node.js开发后台时遇到的错误——'next is not a function'。问题根源在于在路由渲染的位置错误地调用了中间件的方法,导致Promise中未捕获的错误。解决方案是将User.lastLoginTime的调用放置在正确的位置,即'/‘路由之后。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

记录一下今天出现的问题,苦恼了很久,结果原因是写错了位置。
错误地方,不应该在路由渲染的地方调用中间件里的方法,位置写错了,导致报错promise里没有.catch处理错误。

代码

数据库操作

中间件

路由
User.lastLoginTime应该在 ‘ / ’ 后边
报错信息

(node:12708) UnhandledPromiseRejectionWarning: TypeError: next is not a function
    at C:\Users\blog\middleware\user.js:11:5
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:12708) 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:12708) [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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值