Dependencies , DevDependencies & PeerDependencies

Omkar Bhavare
3 min readNov 8, 2023

--

To understand what is dependency lets understand what is package.json file what all data does it contains.

🤔 What is package.json file ? 📦
package.json file is a crucial file in our projects & contains all the project related metadata i.e. project-name , package dependencies , their version number , scripts , repository link etc
It is created using simple “ npm init ” command in the terminal

🤔 Then What is package-lock.json file ?
package-lock.json file provides which version of package is currently being used. (since packages are updated according to their semantic versioning.)

Development Phase: Development phase involves creating and testing software

Production Phase: Production phase involves deploying and running
the software in a live environment for end-users.

🤔 What is dependencies ?
Dependencies includes all the packages used in the project in production phase only.

"dependencies": {
"ejs": "^3.1.9",
"react": "^18.2.0",
"tailwindcss": "^3.3.5"
}

🤔 What is devDependencies ?

DevDependencies contains all the packages that are utilised in the project during it’s development phase , but not in production phase.
Here Jest is a testing library & nodemon is a package used to automatically restart server if any changes are detected in code & both are not used in production phase

"devDependencies": {
"jest": "^29.7.0",
"nodemon": "^3.0.1"
}

command to install devDependencies

npm install -D package-name

🤔 What is peerDependency?

A peer dependency is when a package relies on another package, but expects the project using it to have that dependency already installed, without including it in its own dependencies.

[ Suppose you are a developer ( dependency ) in a company-A ( project ) & to deliver a efficient / desired output you want few QA’s (peerdependency) to perform certain tasks which is supposed to be allocated by the project manager (developer) ]

this is library package which is dependent upon another package
( formatting-library )

// libarary package.json
{
"name": "library",
"version": "2.1.4",
"peerDependencies": {
"formatting-library": "^3.1.1"
}
}

“ library ” is declaring that it needs “formatting-library” with a version compatible with 3.1.1 or higher, but it does not list “formatting-library” as a regular dependency.

{
"name": "myapp",
"version": "1.2.5",
"dependencies": {
"logging-library": "2.1.4",
"formatting-library": "3.2.1"
}
}

“myapp” is the main project, and it explicitly includes both “library” and “formatting-library” in its dependencies. The “library” expects that “myapp” will provide the required version of “formatting-library.”

📚 Earlier Post:

What is NPM ? click below to know more 👇
https://medium.com/@omkarbhavare2406/what-is-npm-40dc291537d4

Demystifying Semantic Vesioning 👇
https://medium.com/@omkarbhavare2406/semantic-versioning-571b07e20904

🔍 Coming up next:
Local & Global Package Installation:
Async & Differ , Minification:
Tree Shaking , Transitive Dependency:

Stay tuned for more insights into the world of ReactJs development! 🚀📦

--

--

Omkar Bhavare

Passionate developer, blogger, and problem solver. Crafting code, sharing insights, and building innovative projects. 🚀