节点js +覆盖会话值

时间:2015-12-17 06:06:29

标签: node.js session

我尝试使用以下代码来覆盖会话值。

var express = require('express');
var session = require('express-session');
var sess;

步骤:1

router.post("/login", function(req, res) {
    var email = "aaa@gmail.com";
    sess = req.session;
    sess.email = email;
    res.send({
        data : sess
    });
});

步骤:2

router.post("/update", function(req, res) {
    var email = "bbb@gmail.com";
    sess = req.session;
    sess.email = reqData.email;
    res.send({
        data : sess
    });
});

步骤:3

router.get("/check", function(req, res) {
    sess = req.session;
    var email = sess.email;
    console.log(email);
    //Here display first value.(aaa@gmail.com)
    //how can i get email value (bbb@gmail.com)?
});

如何覆盖会话值?

第三步需要获得stet-2值(bbb@gmail.com)但是我得到了aaa@gmail.com。

1 个答案:

答案 0 :(得分:0)

您只需使用会话功能,然后尝试

var express = require('express');
var app = express();
var session = require('express-session');
app.use(session({secret: 'keyboard cat', resave: false, saveUninitialized: true,cookie: { path: '/', httpOnly: true, maxAge: 30 * 30000 },rolling: true}));

我认为这有助于你