Reputation: 2019
app.use(express.cookieSession());
...
res.cookie('username', userName, { httpOnly: false});
console.log(res.cookie);
Logs this text:
[Function]
Which is not something that I have seen before. I am a little bit confused about how to set and get cookies in express.
Upvotes: 0
Views: 211
Reputation: 4162
res.cookie
is a function. You are using it to set the cookie in
res.cookie('username', userName, { httpOnly: false});
So your console.log is right.
To see the cookie after you set it you'll need to refresh your browser and then outputting req.cookies
or req.signedCookies
will show you the contents of the cookie that was set.
Take a look at the last line of the cookie section in express guide
Upvotes: 2
Reputation: 5164
Cookies in Express can be read from from req.cookies
.
i.e
app.get('/foo', function(req, res){
console.log(req.cookies);
res.send(200);
});
Also, don't forget to include the cookie parser middleware.
Upvotes: 0