首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nodejs.TypeError: next不是函数

nodejs.TypeError: next不是函数
EN

Stack Overflow用户
提问于 2020-07-30 13:19:32
回答 1查看 153关注 0票数 0

我是个打字新手。现在我想获取接口响应信息(包括Elapsed timeresponse statusapi route).I刚刚在githubresponse-time中找到了一个中间件。我只是在启动时使用了这个中间件。

代码语言:javascript
复制
export default (app: Application) => {
  //some code here
  var responseTime = require('response-time')
  app.use(responseTime(function (req, res, time) {
    //some code here
  }))
  
};

当我npm run dev的时候,我得到了

代码语言:javascript
复制
2020-07-30 11:28:21,929 ERROR 85820 [-/127.0.0.1/-/1ms GET /favicon.ico] nodejs.TypeError: next is not a function
    at responseTime (/Users/lithium/develop/one-authentication-center/node_modules/response-time/index.js:61:12)
    at dispatch (/Users/lithium/develop/one-authentication-center/node_modules/koa/node_modules/koa-compose/index.js:42:32)
    at /Users/lithium/develop/one-authentication-center/node_modules/koa/node_modules/koa-compose/index.js:34:12
    at MidwayApplication.handleRequest (/Users/lithium/develop/one-authentication-center/node_modules/koa/lib/application.js:166:12)
    at MidwayApplication.handleRequest (/Users/lithium/develop/one-authentication-center/node_modules/egg/lib/application.js:211:18)
    at Server.handleRequest (/Users/lithium/develop/one-authentication-center/node_modules/koa/lib/application.js:148:19)
    at Server.emit (events.js:314:20)
    at parserOnIncoming (_http_server.js:777:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17)

pid: 85820

我打开了response-time/index.js,出现的代码错误是

代码语言:javascript
复制
  var fn = typeof opts !== 'function'
    ? createSetHeader(opts)
    : opts

  return function responseTime (req, res, next) {
    var startAt = process.hrtime()

    onHeaders(res, function onHeaders () {
      var diff = process.hrtime(startAt)
      var time = diff[0] * 1e3 + diff[1] * 1e-6

      fn(req, res, time)
    })

    next()
  }
}
EN

回答 1

Stack Overflow用户

发布于 2020-07-30 13:36:09

您传递的不是responseTime的next,而是一个字符串或日期/数字,我看到有'' time '‘作为第三个,我不确定“这里的一些代码”做什么,但似乎正在尝试调用next的时间

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63166632

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档