Difference between dependencies, devDependencies and peerDependencies in npm package.json file?
Table of contents
No headings in the article.
Introduction: Every web development project includes a file called package.json. This file contains project-related metadata. This file instructs npm how to manage the project's dependencies. It also includes other metadata such as the project description, version, and licence. This file is found in the root directory of Node.js project.
To get package.json file
npm init -y
There are 3 types of dependencies in this file
- Dependency - It includes all of the packages used in the project, along with their version numbers. So, if you install any library that is necessary in your project and that can be found in the dependencies object.
Syntax to install a dependency in your project
npm i <package_name>
yarn add <package_name>
After installing the module, head to the package.json file and look for the package with its version in the dependencies object.
- Dev Dependency - There is an object called dev Dependencies in the package.json file, and it contains all the packages that are utilised in the project during its development phase but not in the production phase, along with their version number.
Syntax to install a dev-dependency in your project
npm i <package_name> --save-dev
yarn add <package_name> --dev
After installing the module, head to the package.json file and look for the package with its version in the dependencies object.
- Peer Dependencies - PeerDependencies are packages that must be installed in the application in order to use your package; they represent compatibility. This means that if someone wants to use your package, they must also install the dependencies. "React" is a very common example of peerdependency.