Skip to content

Session

Easy — everyone uses thisNetworking

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."

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