What is the difference between yarn run and npm start?
npm start
is a shortcut for npm run start
Now in terms of running scripts from package.json
, all these are equivalent:
npm run start
npm start
yarn run start
yarn start
npm run myscript
npm myscript
this is an erroryarn run myscript
yarn myscript
This is because run
is not mandatory command for yarn
, but it is for npm
.
Bonus
npr start
- OKnpr myscript
- OK
Put this file somewhere in PATH
, eg. %localappdata%\Programs\Git\cmd
npr.cmd
npm run %*
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, all the below commands work similar!
npm start
npm run start
yarn start
yarn run start
If you have a user defined script named 'app':
npm app
(Does not work!)npm run app
(Works!)yarn app
(Works!)yarn run app
(Works!)
Note: By default start runs node server.js in case not explicitly defined.
It seems yarn run start
is the equivalent of npm start
, which runs the script inside the start
field of the script
field in package.json