https://github.com/nswbmw/N-blog/wiki/%E7%AC%AC1%E7%AB%A0–%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E7%9A%84%E5%8D%9A%E5%AE%A2
正在跟随上面的教程一步一步做,在会话支持那一节中安装 connect-mongo
后,添加:
var MongoStore = require('connect-mongo')(express);
var settings = require('./settings');
和
app.use(express.cookieParser());
app.use(express.session({
// ......
})
}));
之后运行报错:
Error: Most middleware (like session) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.
求问在 Express 4 中该如何处理这个中间件
9 回复
express 4 跟之前很不同。 比如 express.session 和 express.cookieParser 都已经不存在了。 express 和 中间件已经剥离了,除了 express.static。
我改成了这样: var MongoStore = require(‘connect-mongo’)(connect); var settings = require(‘./settings’); var connect = require(‘connect’);
app.use(cookieParser()); app.use(connect.session({ //… }));
我把connect-mongo.js也换成了git上的兼容4.x的版本, 也用npm安装了connect,运行报错: var Store = connect.Store || connect.session.Store; ^ TypeError: Cannot read property ‘Store’ of undefined