Request preferences
Read a preference such as a theme or locale from an incoming request cookie.
Express.js · Pipe
req.cookies is an object populated by cookie-parser with cookies sent by the request. It is empty when no cookies are present; signed cookies belong in req.signedCookies.
After cookie-parser runs, Express exposes incoming cookie name-value pairs through req.cookies. Read a cookie by property name; when the request has no cookies, the object is empty. Cookies signed with a secret are exposed separately through req.signedCookies.
req.cookiesAn object containing cookies sent by the request, or {} when none are present.
const express = require('express');
const cookieParser = require('cookie-parser');
const app = express();
app.use(cookieParser());
app.get('/theme', (req, res) => {
res.json({ theme: req.cookies.theme ?? 'default' });
});
app.listen(3000);This app parses incoming cookies and returns the requested theme, falling back when the cookie is absent.
Read a preference such as a theme or locale from an incoming request cookie.
Inspect an authentication-related cookie before applying application-specific validation.
Pass parsed cookie values to middleware that validates or uses them.
req.signedCookiescookie-parserreq