Skip to content

Cookie

Easy — everyone uses thisNetworking

ELI5 — The Vibe Check

A cookie is a tiny piece of data the server tells your browser to store and send back on every future request. It's how websites remember you're logged in — without cookies, every page would ask you to log in again. Cookies can have expiry dates and security flags.

Real Talk

HTTP cookies are small key-value data stores sent from a server via the Set-Cookie response header and automatically included by the browser in subsequent requests via the Cookie header. Used for session management, authentication, and tracking. Security attributes include HttpOnly, Secure, and SameSite.

Show Me The Code

// Setting a cookie in Express
res.cookie('sessionId', 'abc123', {
  httpOnly: true,   // JS can't access it
  secure: true,     // HTTPS only
  sameSite: 'strict', // CSRF protection
  maxAge: 86400000  // 24 hours in ms
});

// Reading cookies
console.log(req.cookies.sessionId);

When You'll Hear This

"Store the auth token in a cookie with HttpOnly flag." / "Clear all cookies to fix the stale session issue."

Made with passive-aggressive love by manoga.digital. Powered by Claude.