express signed cookies code example

Example 1: express cookies

const express = require('express');
const cookieParser = require('cookie-parser');

const app = express();
app.use(cookieParser());

app.get('/', (req, res) => {
  res.send(req.cookies);
});

app.listen(3000);

Example 2: express signed cookies

var express = require('express');
var cookieParser = require('cookie-parser');

var app = express();
app.use(cookieParser('YOUR-SECRET-SALT'));

app.get('/', (req, res, next) => {
  res.cookie('name', 'value', { signed: true });
  res.send('Success');
});

app.get('/test', (req, res, next) => {
  req.signedCookies.name; // 'value'
});