Skip to main content

Prerequisites

Before installing Express, make sure you have the following installed on your system:
1

Install Node.js

Download and install Node.js version 18 or higher.Verify your installation:
node --version
2

Create a project directory

Create a new directory for your project and navigate into it:
mkdir myapp
cd myapp
3

Initialize your project

Create a package.json file using the npm init command:
npm init
This will prompt you for various project details. You can accept the defaults by pressing Enter, or use -y to skip all prompts:
npm init -y

Installing Express

Express is a Node.js module available through the npm registry. You can install it using your preferred package manager:
npm install express
This will install Express and add it to your package.json dependencies.

Installing with Specific Version

To install a specific version of Express, specify the version number:
npm install [email protected]

Development Installation

If you’re contributing to Express or want to install it as a development dependency:
npm install --save-dev express

Installing the Express Generator (Optional)

The Express application generator (express-generator) is an optional tool that quickly creates an application skeleton:
npm install -g express-generator@4
The generator’s major version should match Express’s major version (e.g., use express-generator@4 with Express 4.x).

Using the Generator

Once installed, you can create a new Express application:
express myapp
cd myapp
Install dependencies:
npm install
Start the application:
npm start
Your application will be available at http://localhost:3000.

Verifying Installation

To verify that Express is installed correctly, create a simple test file:
index.js
const express = require('express')
const app = express()

app.get('/', (req, res) => {
  res.send('Express is installed!')
})

app.listen(3000, () => {
  console.log('Test server running on http://localhost:3000')
})
Run the file:
node index.js
Open your browser and navigate to http://localhost:3000. You should see “Express is installed!” displayed.

Common Installation Issues

If you get permission errors when installing globally, avoid using sudo. Instead, configure npm to install global packages in your home directory:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
Express requires Node.js 18 or higher. Update Node.js using:
If you encounter dependency conflicts, try clearing your npm cache:
npm cache clean --force
rm -rf node_modules package-lock.json
npm install

Next Steps

Quick Start

Create your first Express application

Hello World

Step-by-step Hello World tutorial

Build docs developers (and LLMs) love