Is it possible to run Node.js scripts without invoking `node`?

Whats making your current shell starting the bash is that your current shell (bash?) has no clue about what to do with a file.js. Thats why the gods of unix invented the shebang for:

The character sequence consisting of the characters number sign and exclamation point (#!), when it occurs as the first two characters in the first line of a text file. In this case, the program loader in Unix-like operating systems parses the rest of the first line as an interpreter directive and invokes the program specified after the character sequence with any command line options specified as parameters.

So, in your case I would try to put

 #!/usr/bin/env node

at the top of the script. You can see that beeing applied for example in the ‘inode’ (interactive node.js) shell, which might be another option to fire your scripts.

https://github.com/bancek/node-interactive-shell/blob/master/inode.js

Leave a Comment