JavaScript on the Server with Node.js

Learn Node.js, its event loop, npm and a web framework like Express or Fastify to build HTTP APIs.

Beginner · about 40 hours · difficulty 3/5

Learn first: HTTP in Depth

Node.js runs JavaScript outside the browser on the V8 engine. It is our recommended first backend language because you can use one language across frontend and backend, the package ecosystem (npm) is huge and the job market is large. Pair it with TypeScript as soon as you are comfortable, since types catch many bugs before runtime.

How Node works

Node runs your JavaScript on a single thread with an event loop. I/O (network, disk, database) is non-blocking: you start an operation and continue, and a callback or await resumes when it finishes. This makes Node excellent for I/O-heavy APIs, but a CPU-heavy loop (image processing, big JSON parsing) blocks every other request. Offload such work to worker threads or a separate service.

What to learn

  • Modern JavaScript: async/await, Promises, modules (ESM), destructuring, error handling.
  • npm or pnpm, package.json, semantic versioning and lockfiles.
  • A framework: Express (minimal, ubiquitous), Fastify (fast, schema-first) or NestJS (opinionated, structured).
  • Validating input (Zod or similar), middleware, routing, and centralized error handling.

Pitfalls

  • Unhandled promise rejections crashing the process. Always await or catch.
  • Mixing CommonJS and ESM without understanding the difference.

You are ready to move on when you can build a small CRUD API with routing, validation, error handling and environment-based config, and explain why a synchronous loop hurts every user.

Key concepts

  • Event loop and async I/O
  • async/await and Promises
  • npm, package.json and lockfiles
  • TypeScript
  • Express
  • Fastify
  • NestJS
  • Input validation with Zod
  • Worker threads

Other options for this step

Mini project

Build a TypeScript Express or Fastify API for a bookmarks app with CRUD endpoints, Zod validation, a global error handler and config loaded from environment variables.

Check yourself

What happens to other in-flight requests when one request handler runs a 3-second synchronous loop in Node.js?

Free resources