我的应用程序中出现了这个奇怪的错误。正如您在package.json
中看到的那样,express
版本是> 4.x
。
{
"name": "MyAPI",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"bcrypt": "^0.8.6",
"body-parser": "~1.13.2",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"express": "~4.13.1",
"jade": "~1.11.0",
"morgan": "~1.6.1",
"pg": "^4.5.5",
"pg-hstore": "^2.3.2",
"sequelize": "^3.23.2",
"sequelize-cli": "^2.4.0",
"serve-favicon": "~2.3.0",
"validator": "^5.2.0"
}
}
这是源代码
'use strict';
var express = require('express');
var router = express.Router();
var version = require('../package.json').version;
var sequelize = require('sequelize');
var userAccounts = require('../models').user_account;
router.post('/v' + version + '/register', function (res, req, next) {
userAccounts.create(req.body).then(function () {
next();
return res.sendStatus(200).send({ message: ":D" });
});
});
module.exports = router;
我还尝试将sendStatus
更改为status
,但错误也与status
相同。为什么我会收到这些错误?
答案 0 :(得分:7)
表达式处理函数的参数res
和req
的顺序错误。他们应该是:
function (req, res, next) {}