DEV Community

Dev Shah
Dev Shah

Posted on

Types of Dependencies in package.json

Dependencies

Some dependencies are required by the application to run in a production environment. There are all the libraries and/or modules which are required by the application to function correctly. This dependency can be installed using the following command,

npm install <dependency name>
Enter fullscreen mode Exit fullscreen mode

Development Dependencies

These are the dependencies that are required by the application during development. These dependencies mainly include testing frameworks, build tools, linters, and other such modules which are only required while in the development stage of the application. Dev dependencies can be installed using the following command,

npm install --save-dev <depedency name>
Enter fullscreen mode Exit fullscreen mode

Peer Dependencies

These are the dependencies which are required by the installed dependencies. In other words, let's say you need to install package1 and that package1 has package2 as its dependency, in this case, package2 can be called a peer dependency. In other words, their dependencies can be considered as sub-dependencies. Whenever you install a package that has a peer dependency, the package manager notifies you about it. Subsequently, those dependencies can be installed using the same command as for normal dependencies, that is,

npm install <dependency name>
Enter fullscreen mode Exit fullscreen mode

Optional Dependencies

These are dependencies that are just add-ons to the project. The project would still work completely fine and as expected even without having their dependencies installed. Optional dependencies are automatically installed along with the package.

Top comments (0)