适用于 Express 的简单会话中间件
注意: 从 1.5.0 版本开始,cookie-parser 中间件不再需要用于使此模块正常工作。此模块现在直接在 req/res 上读取和写入 Cookie。使用 cookie-parser 可能会导致问题,如果此模块和 cookie-parser 中的 secret 不相同。
express-session 会在 options 对象中接受以下属性。
var app = express()
app.use(session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: true,
cookie: function(req) {
var match = req.url.match(/^\/([^/]+)/);
return {
path: match ? '/' + match[1] : '/',
httpOnly: true,
secure: req.secure
[npm registry](https://www.npmjs.com/). Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):安全性: 会话 Cookie 的默认值为 secure=false,且没有 sameSite 属性
会话滚动的自定义方式
响应后最大年龄重置
在会话销毁时,Cookie 应立即过期
刷新页面时错误已过期时间。
请求: getSession 方法?
允许使用不同的 Cookie 签名实现
允许异步 genid 函数
[email protected] 的积压任务
在 @expressjs/session 下发布 express-session 包。