This may not be 100% accurate so I implore other, more qualifies, experts to chime in.
NPM is a program, installed as part of the Node.JS environment. It's two main uses (as describe here) are for searching for node.js packages and installing node.js packages.
However, NPM is also capable of understanding "simple" (a relative term) scripts.
When you write a script in your package.json, and issue the NPM command, say "npm start", NPM will read and interpret the script. NPM then searches your node_modules structure for the accompanying binary and executes that binary with the necessary start parameters.
An example would be
"test": "mocha --reporter spec test"
when you issue "npm test", NPM will look for the mocha binary in your node_modules structure. NPM finds mocha initiates the call, passing the reporter command arg (--reporter spec) and the name of the file to be read and executed for the test.
package.json
:)Node.js
runs JavaScript code from command line interface.package.json
doesn't do anything, it just describes what should happen.Node.js
parsespackage.json
and reads it. It's capable of running JS, as I mentioned, which is where the magic comes from.node
isjavascript
. More specifically, how is the script executed? Is it that thebash
script is run by node? Doesnode
understandbash
? Or do they communicate with eachother?exec()
for such purpose), node is no exception.