在使用express使用session时发现怎么使用session都是undefined最后发现
app.use(express.cookieParser());app.use(express.session({secret: "lalala" }));
上面的代码位置不对,应该放在开始位置
app.use(express.cookieParser());app.use(express.session({secret: "lalala" }));app.use(expressLayouts);app.use(express.favicon());app.use(express.logger('dev'));app.use(express.json());app.use(express.urlencoded());app.use(express.methodOverride()); app.use(app.router);
参考资料
http://www.senchalabs.org/connect/session.html