I use the below to set a cookie using express.
res.cookie(\'test\', \'yes\', {
expires: new Date(Date.now() + 365*2*24*60*60*1000),
httpOnly: true
I solved it by adding app.use(express.cookieParser());
above the app.router
.
You need to use express.cookieParser()
before app.router
; middleware is run in order, meaning it's never even reaching cookieParser()
before your route is executed.
Try this:
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
Most middleware (like cookieParser) is no longer bundled with Express and must be installed separately.
Install cookie-parser:
npm install cookie-parser
Usage
var express = require('express')
var cookieParser = require('cookie-parser')
var app = express()
app.use(cookieParser())
https://github.com/expressjs/cookie-parser