cookie-parser:https://www.npmjs.com/package/cookie-parserjavascript
express-session:https://www.npmjs.com/package/cookie-sessionjava
var cookieParser = require('cookie-parser') var session = require('express-session') app.use(cookieParser()) app.use(session({ secret: '...' }))
當退出服務後,會話結束。如何保持會話數據的持久化?mongodb
引入connect-mongoexpress
var mongoStore = require('connect-mongo')(session) app.use(session({ secret: '...', store: new mongoStore({ url: mongodb鏈接地址, collection: 'sessions' }) }))