Ben Borgers

How to access cookies with Express


The best way to access cookies with an Express server is using the cookie-parser middleware package.

Install it:

npm install cookie-parser

And then add it to your server:

const express = require("express")
const app = express()

const cookieParser = require("cookie-parser")

// the rest of your Express server...

You can then access the cookies of any request:

app.get("/", (req, res) => {
const cookies = req.cookies
const token = req.cookies.token

// ...etc