Session
ELI5 — The Vibe Check
A session is the server's way of remembering who you are across multiple requests. Since HTTP is stateless (each request is independent), sessions give it memory. The server creates a session when you log in, stores your info server-side, and gives you a session ID (usually in a cookie) to identify yourself next time.
Real Talk
A web session maintains state across multiple HTTP requests from the same client. The server stores session data (user ID, preferences, cart) indexed by a session ID, which is shared with the client via a cookie or URL parameter. Sessions expire after inactivity or logout.
Show Me The Code
// Express session setup
const session = require('express-session');
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: { secure: true, maxAge: 3600000 }
}));
// Using sessions
app.post('/login', (req, res) => {
req.session.userId = user.id;
res.json({ success: true });
});
When You'll Hear This
"The session expires after 30 minutes of inactivity." / "Store the cart items in the user's session."
Related Terms
Authentication (AuthN)
Authentication is proving you are who you say you are.
Cookie
A cookie is a tiny piece of data the server tells your browser to store and send back on every future request.
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!
Sticky Session
Sticky sessions make sure a user always gets routed to the SAME server, like getting the same cashier every time you visit a store.