Express.js Installation
Now that your environment is ready, it's time to install Express.js in your project. There are two ways to do this: manually installing Express or using the Express Generator tool. Let's learn both methods.
Method 1: Manual Installation (Recommended for Learning)
This method gives you full control and helps you understand the project structure better.
Step 1: Initialize npm in your project
npm init -yThis creates a
package.json file with default settings. This file tracks your project dependencies and scripts.Step 2: Install Express
npm install expressThis downloads Express and adds it to your
package.json dependencies. You'll see a node_modules folder and package-lock.json file.Method 2: Using Express Generator (For Larger Projects)
Express Generator creates a complete project structure with all the boilerplate code.
Step 1: Install Express Generator globally
npm install -g express-generatorStep 2: Generate a new Express app
express my-app --view=ejsThis creates a folder called
my-app with a complete Express app using EJS as the template engine.Step 3: Install dependencies
cd my-appnpm installWhat Gets Installed?
After installation, your project will have:
node_modules/– Contains all Express and its dependencies.package.json– Lists Express as a dependency.package-lock.json– Locks exact versions for consistent installs.
Two Minute Drill
- Run `npm init -y` to create package.json.
- Install Express with `npm install express`.
- Express Generator (`express-generator`) creates complete project structures.
- Manual installation is better for learning; generator is great for production apps.
Need more clarification?
Drop us an email at career@quipoinfotech.com
