EN
Express.js - delete cookie
0 points
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:
xxxxxxxxxx
1npm install cookie-parser
To delete cookies, we use response.clearCookie()
method with specified cookie name (username
).
xxxxxxxxxx
1
const express = require('express');
2
const cookieParser = require('cookie-parser');
3
4
const app = express();
5
6
app.use(cookieParser());
7
8
app.get('/clear-cookie', (request, response) => {
9
response.clearCookie('username');
10
response.send('Cookie cleared');
11
});
12
13
app.listen(3000);
Before:

After:
