Answer the question
In order to leave comments, you need to log in
How to correctly add data to the session after returning a response to the client in node+express?
Like this - it works, but waits for the timeout to end:
app.post('/sessionTest/', urlencodedParser, function (req, res) {
var sess = req.session;
console.log(sess);
if (!req.body.key) {
return res.sendStatus(400);
}
setTimeout(()=>{
sess[req.body.key] = Math.random();
return res.send('Sucess!');
},1000);
});
app.post('/sessionTest/', urlencodedParser, function (req, res) {
var sess = req.session;
console.log(sess);
if (!req.body.key) {
return res.sendStatus(400);
}
setTimeout(()=>{
sess[req.body.key] = Math.random();
},1000);
return res.send('Sucess!');
});
Answer the question
In order to leave comments, you need to log in
in fact, the chest just opened: in case of modifying the session data after returning the response, you just need to call sess.save ()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question