Last modified: Jul 16, 2025 By Alexander Williams

How to Install Express Module in Node.js

Express is a popular web framework for Node.js. It simplifies server creation. This guide will help you install it correctly.

Prerequisites

Before installing Express, ensure you have Node.js installed. Check by running:

 
node -v

If Node.js is installed, you'll see the version. If not, download it from the official website.

Initialize a Node.js Project

First, create a project folder. Then, initialize a Node.js project inside it.

 
mkdir my-express-app
cd my-express-app
npm init -y

This creates a package.json file. It stores project dependencies.

Install Express Module

Use npm to install Express. Run this command in your project folder:

 
npm install express

This downloads Express and adds it to package.json. Wait for the installation to complete.

Verify Installation

Create a simple server to test Express. Make a file named app.js.

 
// Import Express module
const express = require('express');

// Create an Express app
const app = express();

// Define a route
app.get('/', (req, res) => {
  res.send('Hello World!');
});

// Start the server
app.listen(3000, () => {
  console.log('Server running on port 3000');
});

Run the server using Node.js:

 
node app.js

Open your browser and go to http://localhost:3000. You should see "Hello World!".

Common Errors and Fixes

Sometimes, you may encounter errors. Here are common ones and their solutions.

Error: Cannot Find Module

If you see Error: Cannot find module 'express', reinstall Express. Check out our guide on Fix Error: Cannot Find Module in Node.js.

Permission Issues

If installation fails due to permissions, try:

 
sudo npm install express

Or fix npm permissions globally. This avoids using sudo.

Using Express in Your Project

Once installed, you can use Express to build APIs and web apps. Here's a basic example:

 
const express = require('express');
const app = express();

// Middleware to parse JSON
app.use(express.json());

// POST route example
app.post('/data', (req, res) => {
  res.json(req.body);
});

app.listen(3000);

This creates a server that accepts JSON data. Test it with tools like Postman.

Conclusion

Installing Express in Node.js is simple. Follow these steps to avoid errors. For more help, see Fix Node.js Error: Cannot find module.

Now you're ready to build powerful web apps with Express and Node.js. Happy coding!