https://github.com/expressjs/session
参照例子,welcome to the session demo. refresh! 刷新页面每次都显示这个。
将:res.end('welcome to the session demo. refresh!');
修改为:res.end('welcome to the session demo. refresh!'+sess.views);
每次都显示 welcome to the session demo. refresh! 1
是被覆盖了吗?调用 sess.save()
方法也一样。
引用顺序
var express = require('express');
var path = require('path');
var favicon = require('static-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var bodyParser = require('body-parser');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(favicon());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(express.static(path.join(__dirname, 'public')));
app.use(cookieParser());
app.use(session({
secret: 'keyboard cat',
key: 'sid',
cookie: { secure: true }
}))
var routes = require('./routes/index');
var users = require('./routes/users');
app.use('/', routes);
app.use('/users', users);
app.listen(1111);
module.exports = app;