The documentation states that:
During installation, npm will symbolically refer to this file in the / bin prefix for global installations or. / Node_modules / .bin / for local installations.
This means that npm does nothing special for your file and expects it to run on unix. Your bin file can be a perl script, a compiled C program, a shell script, a Ruby script, or even a node.js javascript application.
Therefore, the reason for starting your application is not npm. This is your OS. Thus, your script must be executable (as I said, it can even be compiled binary).
On unix, to automatically execute a script with the correct interpreter, you need sh-bang as the first line in the file. For node.js, I usually use this line:
You can simply use:
but depending on the OS or even the distribution, node.js can be installed in different places. Thus, /usr/bin/env is a program that loads the default environment variables, which includes $PATH , which allows the shell to automatically find where node.js. is installed.
source share