[Fixed] How to get cookie value in expressjs


I’m using cookie-parser, all the tutorial talk about how to set cookie and the time it expiries but no where teach us how to get the value of these cookie


First note that Cookies are sent to client with a server request and STORED ON THE CLIENT SIDE. Every time the user loads the website back, this cookie is sent with the request.

So you can access the cookie in client side (Eg. in your client side Java script) by using


you can test this in the client side by opening the console of the browser (F12) and type


you can access the cookie from the server (in your case, expressjs) side by using


Best practice is to check in the client side whether it stored correctly. Keep in mind that not all the browsers are allowing to store cookies without user permission.

As per your comment, your code should be something like

var express = require('express');
var app = express();

var username ='username';

app.get('/', function(req, res){
   res.cookie('user', username, {maxAge: 10800}).send('cookie set');


Leave a Reply

(*) Required, Your email will not be published