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 installin your project directory, these packages will be installed automatically. For example, if your application uses theexpresspackage, you would list it as a dependency in yourpackage.jsonfile.devDependencies: These are packages that are only needed during development. They are not required to run your application in production. When you runnpm installwith the-devflag, these packages will be installed. For example, if you usemochafor testing, you would list it as adevDependencyin yourpackage.jsonfile.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 apeerDependencyin yourpackage.jsonfile.
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.
-
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 -
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