安装 express-session
npm install express-session --save
引入
var session = require("express-session");
设置官方文档提供的中间件
app.use( session({ secret: 'keyboard cat', resave: false, saveUninitialized: true }) )
设置值 req.session.username = "张三";
获取值 req.session.username