0
0
Node.jsframework~10 mins

Installing packages (dependencies vs devDependencies) in Node.js - Visual Walkthrough

Choose your learning style9 modes available
Concept Flow - Installing packages (dependencies vs devDependencies)
Start: Need a package
Choose package type
dependencies
Install package
Save in package.json
Use package in app or dev
Run npm install to get packages
This flow shows choosing between dependencies and devDependencies, installing the package, saving it in package.json, and using it in the project.
Execution Sample
Node.js
npm install express
npm install --save-dev jest
Installs 'express' as a runtime dependency and 'jest' as a development-only dependency.
Execution Table
StepCommandPackage Typepackage.json EntryEffect
1npm install expressdependencies"dependencies": { "express": "^version" }express added for runtime use
2npm install --save-dev jestdevDependencies"devDependencies": { "jest": "^version" }jest added for development only
3npm installallReads package.jsonInstalls all dependencies and devDependencies locally
4Run appruntimeUses dependencies onlyOnly dependencies are needed to run app
5Run testsdevelopmentUses devDependenciesdevDependencies used during testing
6Exit--Installation complete, packages ready
💡 All packages installed and saved correctly in package.json under proper sections
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
package.json dependencies{}{"express": "^version"}{"express": "^version"}{"express": "^version"}{"express": "^version"}
package.json devDependencies{}{}{"jest": "^version"}{"jest": "^version"}{"jest": "^version"}
node_modules folderemptyexpress installedexpress + jest installedexpress + jest installedexpress + jest installed
Key Moments - 3 Insights
Why do we use --save-dev for some packages?
Packages installed with --save-dev go into devDependencies (see execution_table step 2). They are only needed during development, like testing tools, not when running the app.
What happens if I run npm install without arguments?
npm install reads package.json and installs all dependencies and devDependencies locally (see execution_table step 3). This prepares the project for both running and development.
Are devDependencies installed in production?
By default, devDependencies are not installed in production environments. Only dependencies are installed to keep production lightweight (see execution_table step 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, after which step is 'jest' added to devDependencies?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Check the 'package.json Entry' column for devDependencies in the execution_table rows.
At which step does npm install add all packages to node_modules?
AStep 1
BStep 3
CStep 2
DStep 5
💡 Hint
Look for the step where 'node_modules folder' shows both express and jest installed in variable_tracker.
If you only want packages needed to run the app, which package.json section do you check?
Adependencies
BdevDependencies
Cscripts
DpeerDependencies
💡 Hint
Refer to execution_table step 4 where runtime uses only dependencies.
Concept Snapshot
npm install package: adds package to dependencies for runtime use
npm install --save-dev package: adds package to devDependencies for development only
package.json tracks these sections separately
npm install installs all packages listed
Use dependencies to run app, devDependencies for development tasks
Full Transcript
This lesson shows how to install packages in Node.js projects using npm. When you run 'npm install express', express is added to dependencies in package.json and is needed to run the app. When you run 'npm install --save-dev jest', jest is added to devDependencies and is only needed during development, like testing. Running 'npm install' without arguments installs all packages listed in both dependencies and devDependencies. In production, only dependencies are installed to keep the app lightweight. This helps keep development tools separate from runtime code.