Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Express.js · Pipe

req.cookies

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.

How it works

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.

Syntax

req.cookies

Returns

An object containing cookies sent by the request, or {} when none are present.

Key points

  • req.cookies is populated by cookie-parser with cookies received in the HTTP request.
  • The property is an empty object when the request contains no cookies.
  • Use req.signedCookies for signed cookies rather than reading them from req.cookies.

Common mistakes

  • Signed cookies are not read from req.cookies; use req.signedCookies instead.
  • Handle the empty object when a client sends no cookies.

Example: Read a request cookie

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.

When to use it

Request preferences

Read a preference such as a theme or locale from an incoming request cookie.

Request validation

Inspect an authentication-related cookie before applying application-specific validation.

Middleware processing

Pass parsed cookie values to middleware that validates or uses them.

  • req.signedCookies
  • cookie-parser
  • req

Source: Request Object - Express.js. Checked 2026-10-15.