Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does npm run work?

What happens when I type npm run <command>? Is the <command> passed to the sh shell, like:

sh -c <command>

with additional local variables added to the shell, ie a path to the node_modules/.bin?

I thought npm works only in JavaScript universe by using node, but it seems there's a lot more going on out there. How & and && are handled? Is globstar safe to use?

like image 686
marzelin Avatar asked Mar 01 '16 17:03

marzelin


People also ask

How does npm Run command work?

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.

What happens when npm start?

npm start: npm start script is used to execute the defined file in it without typing its execution command.

Is npm run the same as node?

In short, npm is a package manager, and node is a javascript run time.


1 Answers

npm run-script <command> uses sh -c to run the command, and cmd /d /s /c on windows. (source) It is run by child_process.spawn.

npm env lists the environment that npm uses when it runs commands. The documentation lists some of the things it adds to the environment. This includes everything from package.json, the PATH additions you mentioned and more.

&and && are handled by the shell, but spawn is waiting for the process to end, even when it is put in the background by &. && is working as you are used to in sh.

globstar will work as you expect, except on Windows where you have wildcards instead.

like image 162
bolav Avatar answered Sep 18 '22 13:09

bolav