0
0
Node.jsframework~15 mins

Installing packages (dependencies vs devDependencies) in Node.js - Try It Yourself

Choose your learning style9 modes available
Installing Packages: dependencies vs devDependencies in Node.js
📖 Scenario: You are creating a simple Node.js project. You need to install packages that your project needs to run and packages that help you during development but are not needed when the project runs in production.
🎯 Goal: Learn how to install packages as dependencies and devDependencies using npm. Understand the difference and how to specify each type.
📋 What You'll Learn
Create a package.json file for the project
Install the package express as a dependency
Install the package nodemon as a devDependency
Verify the package.json lists express under dependencies
Verify the package.json lists nodemon under devDependencies
💡 Why This Matters
🌍 Real World
Most Node.js projects need to manage packages that are required to run the app and packages that help during development like testing or live reload tools.
💼 Career
Understanding how to manage dependencies and devDependencies is essential for working on professional Node.js projects and collaborating with teams.
Progress0 / 4 steps
1
Initialize a Node.js project with package.json
Run the command npm init -y in your project folder to create a package.json file with default settings.
Node.js
Need a hint?

Use npm init -y to quickly create a package.json file with default values.

2
Install express as a dependency
Run the command npm install express to add express as a dependency in your project.
Node.js
Need a hint?

Use npm install express to add express to the dependencies section in package.json.

3
Install nodemon as a devDependency
Run the command npm install --save-dev nodemon to add nodemon as a devDependency in your project.
Node.js
Need a hint?

Use npm install --save-dev nodemon to add nodemon to the devDependencies section in package.json.

4
Check package.json for dependencies and devDependencies
Open the package.json file and verify that express is listed under dependencies and nodemon is listed under devDependencies.
Node.js
Need a hint?

Look inside package.json to see the two sections: dependencies and devDependencies. Each should list the correct package.