mongodb session

First

npm i express-session

var expressSession = require("express-session");
app.use(expressSession({
secret:'adsadsadsadsads',
resave:true,
saveUninitialized:true,
cookie:{maxAge:3600000}))

app.get("setsession",function(req,res){
    console.log(req.session);
	console.log(req.session.cookie)
	if(req.session.pageViews){
		req.session.pageViews++;
			req.session.abc=123;
		res.send("you viewed"+req.session.pageViews)
	}else{
		req.session.pageViews=1;
		res.send("one time")
	}
})


Reference:
https://www.npmjs.com/package/express-session

posted @ 2018-11-16 12:05  cyany_blue  阅读(1207)  评论(0编辑  收藏  举报