← Back to Node.js Course | Chapter 7: Express.js Basics | Lesson 2 of 7

Installing Express

Install Express into your project with npm and then require it in your code.

In this page:

  1. Installing Express
Syntax
javascript
npm init -y
npm install express

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

Installing Express

Run npm init -y then npm install express. Express is then in node_modules and listed under dependencies. Use require or import to load it and call express() to create the app.

Note: Pin a major version, for example express@4, to avoid surprise changes.

Example: Installing Express

bash
$ mkdir api && cd api
$ npm init -y
$ npm install express
added 64 packages in 3s
$ node -e "console.log(require('express/package.json').version)"
4.19.2

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
Common Mistakes
  1. Forgetting npm init first
  2. Installing globally
  3. Not saving the dependency
Chapter Summary
  • npm install express
  • It appears in dependencies
  • require it and call express()
  • Pin the major version
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.