Languages
[Edit]
EN

Node.js / Express.js - delete cookie

0 points
Created by:
Wesley
201

In this short article, we would like to delete cookies in Express.js.

Note:

To be able to work with cookies in Express.js, we will use cookie-parser middleware, so use:

npm install cookie-parser

 Check this article to learn how to create cookie - link.

Delete cookie example

To delete cookies, we use response.clearCookie('cookie name') method.

const express = require('express');
const cookieParser = require('cookie-parser');

const app = express();

app.use(cookieParser());

app.get('/clear-cookie', (request, response) => {
    response.clearCookie('username');
    response.send('Cookie cleared');
});

app.listen(3000);

 Before:

Above we have cookie username = john
Above we have cookie username = john

After:

After entering localhost:3000/clear-cookie
Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join