Cookie
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."
Related Terms
Header
Headers are the metadata attached to HTTP requests and responses — information about the information.
HTTP (HyperText Transfer Protocol)
HTTP is the language your browser uses to ask websites for stuff. You type a URL, your browser shouts 'hey, give me that page!
Session
A session is the server's way of remembering who you are across multiple requests.