我遇到了一些不再使用NODE.js的中间件问题 我就是这样做的:
但我仍然遇到同样的错误:"大多数中间件都是bla bla bla ..."
var express = require('express');
var mongoose = require('mongoose');
var path = require('path');
var bodyParser = require('body-parser');
var config = require('config');
var session = require('express-session');
var app = express();
var IS_DEV = (app.get('env') === 'development');
var MongoStore = require('connect-mongo')(express);
app.use(session({
secret: config.get('session:secret'),
key: config.get('session:key'),
cookie: config.get('session:cookie'),
store: new MongoStore({mongoose_connection: mongoose.connection})
}));
已安装软件包,我在node_modules
文件夹中看到它。而且我没有看到任何错误:session is undefined
我做错了什么?
顺便说一下express-error-handler
包
性反应:
Error: Most middleware (like session) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.
[1] at Function.Object.defineProperty.get (C:\Work\todoapp\node_modules\express\lib\express.js:99:13)
[1] at connectMongo (C:\Work\todoapp\node_modules\connect- mongo\src\index.js:48:43)
[1] at Object.<anonymous> (C:\Work\todoapp\app.js:10:42)
[1] at Module._compile (module.js:409:26)
[1] at Object.Module._extensions..js (module.js:416:10)
[1] at Module.load (module.js:343:32)
[1] at Function.Module._load (module.js:300:12)
[1] at Module.require (module.js:353:17)
[1] at require (internal/module.js:12:17)
[1] at Object.<anonymous> (C:\Work\todoapp\bin\www:7:11)
[1] at Module._compile (module.js:409:26)
[1] at Object.Module._extensions..js (module.js:416:10)
[1] at Module.load (module.js:343:32)
[1] at Function.Module._load (module.js:300:12)
[1] at Function.Module.runMain (module.js:441:10)
[1] at startup (node.js:139:18)
[1] at node.js:968:3
[1] Program node --debug ./bin/www exited with code 1
[1]
答案 0 :(得分:0)
由于您使用的是Express 4,connect-mongo
的设置不正确。
应该是:
var session = require('express-session');
...
var MongoStore = require('connect-mongo')(session);
^^^^^^^ not `express`