LOGBOOK

HELP

Quiz Entry - updated: 2026.06.20

How do you set a cookie in Express.js?

Call res.cookie(key, value, options) on the response object to send a Set-Cookie header.

function (req, res) {
  res.cookie('lastUsedName', 'Anna Muster');
  // ... rest of response
}

Common options:

  • maxAge - expiration time in milliseconds
  • httpOnly - prevents JavaScript access (security)
  • secure - only send over HTTPS

Requires the cookie-parser middleware to be installed.

From Quiz: WEBT / User Sessions | Updated: Jun 20, 2026