Languages
[Edit]
EN

Express.js - delete cookie

0 points
Created by:
Wesley
501

In this short article, we would like to show you how 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

 

Delete cookie example

To delete cookies, we use response.clearCookie() method with specified cookie name (username).

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

See also

  1. Express.js - add cookie 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
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