What's the difference between dependencies, devDependencies, and peerDependencies in NPM package.json file?
When you create a new Node.js project, you’ll notice a package.json
file in the root directory. This file contains metadata about your project, including the dependencies required to run it. There are three types of dependencies that can be specified in the package.json
file: dependencies
, devDependencies
, and peerDependencies
. Here’s what each of them means:
dependencies
: These are packages that your application needs to run in production. When you runnpm install
in your project directory, these packages will be installed automatically. For example, if your application uses theexpress
package, you would list it as a dependency in yourpackage.json
file.devDependencies
: These are packages that are only needed during development. They are not required to run your application in production. When you runnpm install
with the-dev
flag, these packages will be installed. For example, if you usemocha
for testing, you would list it as adevDependency
in yourpackage.json
file.peerDependencies
: These are packages that your package relies on but expects the consumer to provide. They are not installed automatically when someone installs your package. Instead, when someone installs your package, they will get a warning if the specified packages are not found in their node modules. For example, if your package relies onreact
, you would list it as apeerDependency
in yourpackage.json
file.
Here’s an example package.json
file that includes all three types of dependencies:
{
"name": "my-app",
"version": "1.0.0",
"dependencies": {
"express": "^4.17.1"
},
"devDependencies": {
"mocha": "^9.1.3"
},
"peerDependencies": {
"react": "^17.0.2"
}
}
In this example, express
is a dependency
, mocha
is a devDependency
, and react
is a peerDependency
.
-
Where does node.js store logs?
Node.js doesn’t store logs in the file. Logs are printed into the STDERR and output is printed into the STDOUT. However, you can change that when you runt the javascript code from the shell and red...
Questions -
How do I pass command line arguments to a Node.js program and receive them?
In Node.js, you can pass command line arguments to your script the same as you would for any other command line application. Simply type your arguments after the script path separated with a space ...
Questions
Make your mark
Join the writer's program
Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.
Write for usBuild on top of Better Stack
Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.
community@betterstack.comor submit a pull request and help us build better products for everyone.
See the full list of amazing projects on github