Q1. How do you install Express.js?
After creating a package.json file, run:
The
For development-only tools, you might use
npm install express --save
This installs Express and adds it to your dependencies in package.json.The
--save flag ensures it's saved in the dependencies list.For development-only tools, you might use
--save-dev.Q2. What is the difference between --save and --save-dev?
For Express, you always use
--save adds the package to dependencies (required for the app to run in production).--save-dev adds to devDependencies (only needed during development, like testing libraries).For Express, you always use
--save because it's required to run your app.Q3. Where is Express installed in your project?
Express is installed in the
This folder contains all the dependencies.
You shouldn't modify this folder manually.
The
The
node_modules folder.This folder contains all the dependencies.
You shouldn't modify this folder manually.
The
package-lock.json file locks the exact versions installed.The
node_modules folder should be ignored in version control (add to .gitignore).Q4. How do you verify that Express is installed correctly?
Check your
Also, you can check the
To test, create a simple
package.json file to see if express appears in the dependencies list.Also, you can check the
node_modules folder for an express folder.To test, create a simple
app.js file that requires express and run it with node app.js.Q5. Can you install Express globally?
You can install Express globally with
Each project should have its own local dependencies to avoid version conflicts.
Global installation might be used for command-line tools, but for framework libraries, always install locally.
npm install -g express, but it's not recommended.Each project should have its own local dependencies to avoid version conflicts.
Global installation might be used for command-line tools, but for framework libraries, always install locally.
