Installing Express
Install Express into your project with npm and then require it in your code.
In this page:
Syntax
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
$ 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
- Forgetting npm init first
- Installing globally
- 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: