Installing Express

Create a project with npm and add Express as a dependency.

Syntaxnpm install express

Express is installed from npm, the Node.js package manager. You need Node.js installed first.

Step by step

  1. Create a folder and move into it.
  2. Run npm init -y to create a package.json.
  3. Run npm install express to add Express.

This creates a node_modules folder and records express in your package.json dependencies. You are ready to write your first server.

Example

Example · bash
mkdir my-app
cd my-app
npm init -y
npm install express

When to use it

  • A developer initialises a new Node.js project with npm init and adds Express so the team can start building API routes immediately.
  • A CI/CD pipeline runs npm install to restore Express and its transitive dependencies in a clean Docker build layer.
  • A monorepo workspace adds Express as a dependency only in the packages/api subfolder to keep the web package lightweight.

More examples

Init project and install Express

Creates a new Node project with default settings and adds Express as a production dependency.

Example · bash
mkdir my-app && cd my-app
npm init -y
npm install express

Verify Express in package.json

Shows how Express appears in package.json after installation, using a semver caret range.

Example · json
{
  "name": "my-app",
  "version": "1.0.0",
  "dependencies": {
    "express": "^5.0.0"
  }
}

Import and confirm installation

Requires Express and logs the installed version to confirm the dependency is correctly resolved.

Example · js
const express = require('express');
console.log('Express version:', require('express/package.json').version);

const app = express();
app.get('/ping', (req, res) => res.send('pong'));
app.listen(3000);

Discussion

  • Be the first to comment on this lesson.