I found serval node.js projects that have this at top of their app.js
(as in this openshift program):
#!/bin/env node
What does this mean? How does this work? Where is it useful?
I found serval node.js projects that have this at top of their app.js
(as in this openshift program):
#!/bin/env node
What does this mean? How does this work? Where is it useful?
The full line from your example is:
#!/bin/env node
This simply means that the script should be executed with the first executable named 'node' that's found in your current PATH.
The shebang (#!) at the start means execute the script with what follows. /bin/env is a standard unix program that looks at your current environment. Any argument to it not in a 'name=value' format is a command to execute. See your env manpage for further details.
./app.js
instead of needing to type node app.js
. For an example where it's useful have a look at stackoverflow.com/questions/14517535/…
Feb 25, 2013 at 8:03
env
is a shell command used to specify an interpreter.
env
will find the location of node
in your $PATH. People sometimes do #!/bin/node
or #!/usr/local/bin/node
but the problem is, you don't know where the person may have their copy of node. So env
program finds that for you.
Feb 25, 2013 at 6:19