Chapter 5

Node.js

Node.js is a JavaScript runtime that lets you run JavaScript on a server or your local machine, outside the browser. It is built on Chrome’s V8 engine.

Most modern web development tools (Vite, webpack, Create React App, and others) require Node.js to be installed. You can also use it to build backend apps, REST APIs, and command-line tools.

Before you start

You should be comfortable with the following before diving into Node.js:

  • JavaScript fundamentals: variables, functions, arrays, objects, arrow functions
  • Promises and async/await
  • Basic command-line usage

If any of those feel shaky, start with the JavaScript section first.

Where to start

Work through these pages in order if you are new to Node.js:

  1. Installation : install Node.js and npm using nvm
  2. Running Node.js : the REPL, running scripts, and npm scripts
  3. npm : installing packages, package.json, and dependencies
  4. Environment Variables : dotenv and process.env
  5. Modules : CommonJS require() and ES module import/export
  6. Core Modules : built-in Node.js modules
  7. File System : reading and writing files
  8. HTTP Server : creating a basic server
  9. Express : building web apps and APIs with Express
  10. Project Structure : organising a Node.js project

Useful tools

  • nodemon: automatically restarts your app when files change during development
  • dotenv: loads environment variables from a .env file into process.env
  • Express: the most widely used Node.js web framework
  • Postman or Thunder Client (VS Code extension): test your API endpoints