Express.js req.cookies Property

Last Updated : 26 Aug, 2026

The req.cookies property contains the cookies sent by the client in an HTTP request. It is populated by the cookie-parser middleware and allows Express applications to read cookie values from incoming requests.

frame_3274

Syntax:

req.cookies

Parameter: No parameters. 

Return Value: Object

Installation of the Express module

You can visit the link to Install the express module. You can install this package by using this command.

npm install express cookie-parser

After installing the express module, you can check your express version in the command prompt using the command.

npm version express

After that, you can just create a folder and add a file, for example, index.js. To run this file you need to run the following command.

node index.js

Project Structure:

NodeProj

Example 1: Reading a Cookie from the Request

javascript
const express = require('express');
const cookieParser = require('cookie-parser');
const app = express();
const PORT = 3000;
app.use(cookieParser());
app.get('/set-cookie', (req, res) => {
    res.cookie('website', 'GeeksforGeeks');
    res.send('Cookie has been set');
});
app.get('/read-cookie', (req, res) => {
    console.log(req.cookies);
    res.send(`Website: ${req.cookies.website}`);
});
app.listen(PORT, () => {
    console.log(`Server listening on PORT ${PORT}`);
});

Steps to run the Program

Run the index.js file using the below command:

node index.js

Output:

Console Output:

Server listening on PORT 3000

Browser Output:

Now first open your browser and go to http://localhost:3000/set-cookie, now you can see the following output on your browser:

Screenshot-2026-08-12-120439

Now open the second link http://localhost:3000/read-cookies on the browser, now you can see the following output:

Screenshot-2026-08-12-120426

Final Console Output:

Screenshot-2026-08-12-121622

Example 2: Reading Multiple Cookies 

javascript
const express = require('express');
const cookieParser = require('cookie-parser');
const app = express();
const PORT = 3000;
app.use(cookieParser());
app.get('/set-cookies', (req, res) => {
    res.cookie('name', 'GeeksforGeeks');
    res.cookie('language', 'JavaScript');
    res.send('Cookies have been set');
});
app.get('/read-cookies', (req, res) => {
    console.log(req.cookies);
    res.json(req.cookies);
});
app.listen(PORT, () => {
    console.log(`Server listening on PORT ${PORT}`);
});

Steps to run the Program

Run the index.js file using the below command:

node index.js

Browser Output: Now open your browser and make a GET request to http://localhost:3000/set-cookies, now you can see the following output on your browser:

Screenshot-2026-08-12-120439

Now open the second link http://localhost:3000/read-cookie on the browser, now you can see the following output:

Screenshot-2026-08-12-122257

Console Output:

Screenshot-2026-08-12-122347

Working of req.cookies

  • The client sends an HTTP request containing cookies.
  • The cookie-parser middleware parses the cookies.
  • Express makes the parsed cookies available through req.cookies.
  • The route handler can access individual cookies using their names.
  • The application can use these values to process the request.

Use Cases of req.cookies

  • Reading user preferences stored in cookies.
  • Accessing session-related cookie values.
  • Retrieving authentication-related cookie data.
  • Managing user-specific settings.
  • Reading application-specific cookie values.

Reference: https://expressjs.com/en/4x/api.html#req.cookies

Comment