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?
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.
npm start: npm start script is used to execute the defined file in it without typing its execution command.
In short, npm is a package manager, and node is a javascript run time.
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.
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