res.clearCookie()

Clears a cookie by setting it to expire immediately.

Since Express 4 Spec ↗

Syntax

res.clearCookie(name[, options])

Parameters

NameTypeRequiredDescription
name string Yes The cookie name to clear.
options object No Must match the `path`/`domain`/`secure`/`sameSite` used when the cookie was set.

Returns

Response — The response object.

Examples

app.post('/logout', (req, res) => {
  res.clearCookie('sid');
  res.sendStatus(204);
});
Output
Set-Cookie: sid=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT
app.post('/logout', (req, res) => {
  res.clearCookie('sid', { path: '/app', httpOnly: true });
  res.redirect('/');
});

Notes

The options (especially `path` and `domain`) must match those used in `res.cookie`, or the browser keeps the original cookie. Clearing is done by sending an expired `Set-Cookie`; there is no real server-side deletion.

See also