session数据在服务器开启时存在,服务器关闭也会随之消失
var express=require("express");
var app=express();
var session=require("express-session");
app.use(session({
secret:"keyboard cat",
resave:false,
saveUninitialized:true
}));
app.get("/",function(req,res){
if(req.session.login){
res.send("欢迎您:"+req.session.username);
}else{
res.send("您还没有登陆");
}
})
app.get("/login",function(req,res){
req.session.login=true;
req.session.username="kaola";
res.send("您已成功登陆");
})
app.listen(3000,"127.0.0.1");