Node.js and npm Setup
Before you write a single line of Express.js code, you need two tools installed on your computer: Node.js and npm. Node.js runs JavaScript outside the browser, and npm (Node Package Manager) downloads and manages code libraries like Express. This topic walks you through installing both and verifying they work correctly.
What Node.js and npm Actually Are
Imagine you want to run a Python script — you need Python installed first. The same rule applies to JavaScript outside the browser. Node.js is the engine that runs JavaScript on your computer or server. npm comes bundled with Node.js automatically, so one installation gives you both.
┌─────────────────────────────────────────────┐ │ Your Computer │ │ │ │ ┌───────────┐ ┌──────────────────┐ │ │ │ Node.js │ + │ npm │ │ │ │ (runs JS) │ │ (downloads libs) │ │ │ └───────────┘ └──────────────────┘ │ │ ↓ ↓ │ │ Your Express.js Application runs here │ └─────────────────────────────────────────────┘
npm connects to a massive online library of over two million packages. When you type a command to install Express, npm fetches the Express code from that library and saves it inside your project folder.
Step 1: Download Node.js
Visit the official Node.js website at nodejs.org. You see two download options on the homepage:
┌──────────────────────────────────────────────────┐ │ nodejs.org Downloads │ ├───────────────────────┬──────────────────────────┤ │ LTS Version │ Current Version │ │ (Long Term Support) │ (Latest Features) │ │ │ │ │ ✓ Stable │ ✓ Newest features │ │ ✓ Recommended │ ✗ May have small bugs │ │ ✓ Best for learning │ ✗ Not for beginners │ └───────────────────────┴──────────────────────────┘
Always download the LTS version when you are learning or building production applications. It receives security updates and bug fixes for years, making it the safer choice.
Step 2: Run the Installer
Open the downloaded file and follow the installation steps for your operating system:
On Windows
Double-click the .msi installer file. Click Next through each screen and accept the license agreement. The installer places Node.js in your system PATH automatically, which means your terminal can find and run the node command from any folder.
On macOS
Double-click the .pkg file and follow the prompts. Alternatively, if you use Homebrew, open your terminal and run brew install node. Homebrew handles everything automatically.
On Linux (Ubuntu/Debian)
Open your terminal and run these commands one at a time:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt-get install -y nodejs
Step 3: Verify the Installation
After installation finishes, open your terminal (Command Prompt on Windows, Terminal on macOS and Linux). Type the following commands and press Enter after each one:
node --version npm --version
You should see version numbers printed on screen, like this:
$ node --version v20.11.0 $ npm --version 10.2.4
If you see version numbers, both tools installed correctly. If you see an error like "command not found," restart your terminal and try again. A fresh terminal session picks up the updated PATH settings.
Understanding the Project Folder Structure
Every Express project lives inside its own folder. Here is how a typical Express project looks once set up:
my-express-app/ │ ├── node_modules/ ← Downloaded packages (never edit this) ├── package.json ← Project info and dependency list ├── package-lock.json ← Exact version record of every package └── app.js ← Your main application file
The node_modules folder holds all downloaded packages. Never manually edit files inside it. The package.json file acts like a recipe card — it lists every package your project needs and the project's basic details.
Step 4: Create Your Project Folder
Open your terminal and create a new folder for your first Express project. Run these commands:
mkdir my-express-app cd my-express-app
mkdir creates the folder. cd moves you inside it. All future commands run from inside this folder.
Step 5: Initialize the Project with npm
Inside your project folder, run this command:
npm init -y
The -y flag tells npm to accept all default settings automatically. This creates a package.json file in your folder. Open it and you will see something like this:
{
"name": "my-express-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
This file tracks your project name, version, and every package you install. Treat it as your project's ID card.
npm Commands You Will Use Often
┌──────────────────────────────────────────────────────────────┐ │ Common npm Commands │ ├──────────────────────────┬───────────────────────────────────┤ │ npm init -y │ Create a new package.json │ │ npm install express │ Download and install Express │ │ npm install │ Install all listed dependencies │ │ npm uninstall express │ Remove a package │ │ npm run start │ Run the "start" script │ │ npm list │ Show installed packages │ └──────────────────────────┴───────────────────────────────────┘
The node_modules Folder and .gitignore
When you install packages, npm creates a node_modules folder that can contain thousands of files. You never upload this folder to GitHub or send it to teammates. Instead, everyone runs npm install on their own machine to download the packages listed in package.json.
Create a file called .gitignore in your project root and add this line inside it:
node_modules/
This tells Git to ignore the entire folder. Your repository stays small, and collaborators install their own copy of the packages locally.
Checking Your Node.js Version for Express Compatibility
Express.js version 4 (the most widely used version) requires Node.js version 0.10 or higher. Any LTS version from the last three years works perfectly. Express.js version 5 requires Node.js version 18 or higher.
┌─────────────────────────────────────────┐ │ Express / Node.js Compatibility │ ├──────────────────┬──────────────────────┤ │ Express 4.x │ Node.js 0.10+ │ │ Express 5.x │ Node.js 18+ │ └──────────────────┴──────────────────────┘
Summary
Node.js lets you run JavaScript on your computer, and npm manages packages like Express. Download the LTS version of Node.js from nodejs.org, run the installer, then verify with node --version and npm --version. Create a project folder, run npm init -y to generate a package.json file, and add a .gitignore file to exclude node_modules. Your environment is now ready for Express development.
