Node.js Backend Fundamentals

Lesson 4 of 6

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.

📝 Express Quiz

Passing score: 70%
  1. 1.Which middleware parses incoming JSON request bodies?

  2. 2.What HTTP method is typically used to create a new resource?

  3. 3.Middleware functions execute after the final route handler sends its response.