npm start: npm start script is used to execute the defined file in it without typing its execution command. Package.json file "scripts"{ "start":"node index.js" } index.js.
npm run sets the NODE environment variable to the node executable with which npm is executed. If you try to run a script without having a node_modules directory and it fails, you will be given a warning to run npm install , just in case you've forgotten.
Few things to understand: npm: run command is mandatory to execute user defined scripts. yarn: run command is not mandatory to execute user defined scripts. start command is not a user defined script name, so you may not need to specify run command to execute it.
So npm start runs the node script that is listed under start in the package. json. As in the article that cbr mentioned in a comment, in the case of create-react-app , this happens: A new instance of the WebpackDevServer from the library of the same name is created, passing in the compiler and configuration.
npm test
, npm start
, npm restart
, and npm stop
are all aliases for npm run xxx.
For all other scripts
you define, you need to use the npm run xxx
syntax.
See the docs at https://docs.npmjs.com/cli/run-script for more information.
npm start
is the short form for npm run start
. So, its one and the same thing.
One interesting thing to note is,
If the scripts
object does not have a "start"
property in package.json
file, npm start
or npm run start
from command line will run node server.js
by default.
But if the scripts
object in package.json has "start"
property, it overrides node server.js
and executes the command in "start"
property.
See - https://docs.npmjs.com/cli/v7/commands/npm-start#description
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With