req.cookies

An object of cookies sent by the client, populated by cookie-parser.

Since Express 4 (via cookie-parser) Spec ↗

Syntax

req.cookies

Returns

object — Cookie names mapped to values (requires cookie-parser).

Examples

import cookieParser from 'cookie-parser';

app.use(cookieParser());

app.get('/me', (req, res) => {
  res.send(`session: ${req.cookies.sid}`);
});
Output
$ curl --cookie 'sid=abc123' localhost:3000/me
session: abc123
app.get('/theme', (req, res) => {
  res.json({ theme: req.cookies.theme ?? 'light' });
});
Output
{"theme":"light"}

Notes

Requires the `cookie-parser` middleware; without it `req.cookies` is undefined. Signed cookies appear in `req.signedCookies` instead. Treat cookie values as untrusted user input.

See also