express cookie parser code example

Example 1: express get cookie

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

app.get('/', (req, res) => {
  console.log('Cookies: ', req.cookies);
  console.log('Signed Cookies: ', req.signedCookies);
});

app.listen(3000);

Example 2: npm cookie-parser

npm i cookie-parser

Example 3: 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);

Tags:

Misc Example