Reputation: 31
In almost all of the docs I've come across so far, most of the time I have seen the start and the dev script being used for a similar kind of functionality. following are 2 examples:
1.
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index",
"dev": "nodemon index"
},
"scripts": {
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
"start": "npm run dev",
So, please help me in understanding, what exactly is the difference between the two in package.json file used for NodeJs. Under what circumstances does mentioning the 2 at the same time make sense.
P.S: I'm new to javascript and node.js. Hence please forgive in case of a silly mistake. Thanks in advance :)
Upvotes: 2
Views: 9173
Reputation: 166
Start is a script handled by default by npm. You can use it without the keyword run:
npm start
dev
is a custom script, the name has no significance fr npm. You need to use the keyword run
:
# npm run <script name>
npm run dev
documentation for start: https://docs.npmjs.com/cli/v6/commands/npm-start
documentation for run-script: https://docs.npmjs.com/cli/v6/commands/npm-run-script
In other words, start
will override the default npm command. By default, npm will run node index.js
on start. The start script always exists even if you don't declare it. That is not the case for dev
.
Upvotes: 2