Difference between Dependencies, devDependencies and peerDependencies
Dependencies | devDependencies | peerDependencies |
---|---|---|
A dependency is a library that a project needs to function effectively. | DevDependencies are the packages a developer needs during development. | A peer dependency specifies that our package is compatible with a particular version of an npm package. |
If a package doesn’t already exist in the node_modules directory, then it is automatically added. | As you install a package, npm will automatically install the dev dependencies. | peerDependencies are not automatically installed. You need to manually modify your package.json file in order to add a Peer Dependency. |
These are the libraries you need when you run your code. | These dependencies may be needed at some point during the development process, but not during execution. | Peer dependencies are only encountered when you publish your own package, that is, when you develop code that will be used by other programs. |
Included in the final code bundle. | Included in the final code bundle . | Can be included only when you are publishing your own package. |
Dependencies can be added to your project by running : npm i <package_name> |
Dev dependencies can be added to your project by running : npm i <package_name> |
Change the package.json file manually. |
Difference between dependencies, devDependencies and peerDependencies
Every web application project typically includes a file named package.json, which serves as a repository of essential project metadata. This file encompasses information ranging from dependencies and their respective versions to development dependencies and peer dependencies.
Run the following command to initialize the project from the root directory of your project:
npm init -y