Course page
Log in

You are watching a free preview. Enroll to open all 24 lessons, track progress and ask the course tutor.

Enroll for $39.99

Section 1: Node.js and Express basics

How a Node.js server works

Video 8 min Lesson 1 of 24 Sample clip Preview

Node.js is a JavaScript runtime built on the V8 engine. It lets JavaScript run outside the browser, with access to the file system, the network and operating system features. For servers, its key feature is non blocking I/O: while one request waits for the database, Node handles other requests on the same thread using the event loop.

This makes Node efficient for APIs that spend most of their time waiting on databases and other services. It is less suited to heavy CPU work, like video encoding, inside request handlers, because that blocks every other request until it finishes.

What a web server does

At its core, an HTTP server:

  1. Listens on a port for incoming requests.
  2. Reads the method, URL, headers and body.
  3. Decides what code should handle it, called routing.
  4. Sends back a status code, headers and a body.

Node's built in http module can do all of this, but you would write a lot of repetitive code for parsing bodies, matching routes and handling errors. Express is a small framework that adds routing and a middleware system on top, without hiding how HTTP works.

Why Express 5

Express has been around for a long time, which means a huge ecosystem of middleware and answers to almost every question online. Express 5, released as the stable major version after a long development period, modernises it:

  • Errors thrown in async handlers and rejected promises are passed to your error handler automatically. In Express 4, an unhandled rejection in a route could leave the request hanging.
  • Route path matching was updated and made stricter, with some older syntax removed.
  • Support for very old Node.js versions was dropped.

If you maintain Express 4 apps, a later lesson covers the main migration points.

Modern Node features we will use

  • node --watch restarts the server when files change, without extra tools.
  • node --env-file=.env loads environment variables from a file.
  • The built in test runner, node --test, and the node:assert module.
  • Native fetch for calling other APIs.

These remove several dependencies that older tutorials still install.

Recipebox

Our API stores recipes for users. A recipe has a title, ingredients, steps, tags and a visibility setting. Users can make collections public and share a link. Simple, but full of real decisions about validation, permissions and data modelling.

← → switch lessons