在我的app.js中我有:
var express = require('express')
var path = require('path');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var mongo = require('mongodb');
var flash = require('connect-flash');
....
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser('3mKay'));
app.use(require('stylus').middleware(path.join(__dirname, 'public')));
app.use(express.session({ secret: 'thisISmyS3cR3t'}));
这在Heroku中与以下消息崩溃。
Error: Most middleware (like session) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.
at Function.Object.defineProperty.get (/app/node_modules/express/lib/express.js:89:13)
at Object.<anonymous> (/app/app.js:25:17)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
我跑了,所以它确实存在于package.json文件中:
npm install express-sessions --save
"dependencies": {
....
"express": "~4.8.6",
"express-session": "^1.8.1",
"passport": "^0.2.1",
"passport-local": "^1.0.0",
....
当我注释掉
时,它工作正常app.use(express.session({ secret: 'thisISmyS3cR3t'}));
我也尝试了以上的变体,但它给出了相同的错误信息。可能导致这种情况发生的任何想法?我可能忽视的东西......
答案 0 :(得分:1)
安装后,您必须在代码中实际使用它:
var express = require('express');
var session = require('express-session');
var path = require('path');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var mongo = require('mongodb');
var flash = require('connect-flash');
....
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser('3mKay'));
app.use(require('stylus').middleware(path.join(__dirname, 'public')));
app.use(session({ secret: 'thisISmyS3cR3t'}));