Building an Express Server
Express is the most popular web framework for Node.js.
import express from 'express';
const app = express();
app.use(express.json());
app.get('/api/health', (req, res) => {
res.json({ status: 'ok' });
});
app.listen(4000, () => console.log('Listening on :4000'));
Server code runs in Node.js, not in the browser playground, you'll run this for real in the final project.
Key concepts
- Routes map an HTTP method + path to a handler.
- Middleware functions run in order before your handler (parsing, auth, logging).
- req / res, the request and response objects.