Build HTTP APIs with routing, middleware, validation, controllers, and error handling.
Lessons
Set, read, and clear cookies with cookie-parser.
Working with Cookies is easiest to learn by reading the example, changing it, and observing the result.
// npm install cookie-parser
import express from 'express';
import cookieParser from 'cookie-parser';
const app = express();
app.use(cookieParser());
app.get('/set', (req, res) => {
res.cookie('theme', 'dark', { httpOnly: true, sameSite: 'lax' });
res.json({ saved: true });
});
app.get('/read', (req, res) => res.json({ theme: req.cookies.theme }));
app.listen(3000);Practice the Working with Cookies example in a small scratch file, then explain what changed and why.