Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between yarn run and npm start?

Is yarn run intended to be the equivalent of npm start?

like image 472
daniely Avatar asked Nov 15 '16 20:11

daniely


People also ask

What's the difference between yarn and npm?

The main difference between NPM and Yarn is the package installation process. Yarn installs packages in parallel. Yarn is optimized to fetch and install multiple packages at once. NPM will perform a serial installation process.

What is the difference between npm start and npm run start?

npm start is the short form for npm run start . So, its one and the same thing. Show activity on this post.

What does yarn run do?

The yarn run command is used to run a script that you defined in the script section of your package. json file. When there is a defined script object in your package, running this command will run the specified [script].

What is npm start used for?

'npm start' is used for executing a startup script without typing its execution command.


Video Answer


3 Answers

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

like image 185
daniely Avatar answered Oct 19 '22 20:10

daniely


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.

like image 42
Chandrashekhar Naik Avatar answered Oct 19 '22 20:10

Chandrashekhar Naik


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 error
yarn run myscript
yarn myscript

This is because run is not mandatory command for yarn, but it is for npm.


Bonus

npr start - OK
npr myscript - OK

Put this file somewhere in PATH, eg. %localappdata%\Programs\Git\cmd

npr.cmd
npm run %*
like image 17
Qwerty Avatar answered Oct 19 '22 20:10

Qwerty