Im trying to set cookies for my website using node.js and express.js. Heres a simplified version of my code:
var express = require('express');
var cookieParser = require('cookie-parser');
var app = express();
app.use(cookieParser());
app.post('/testCookies', function(req, res) {
console.log(req.cookies); //empty object
res.cookie('username', 'test');
console.log(req.cookies); //still an empty object
res.end();
});
I tried POSTing twice in case the cookies somehow get set after the request (im not very familiar with cookies yet) but it doesn't change anything. The console does not show any errors.