Install my nodejs script to linux bin

If I has my own custom script called do.js that run as a command line application that process parameters like the following:

node do.js arg1 arg2 arg3

How can I install this application to bin that I run it like:

do arg1 arg2 arg3

How this can be done ?

First, the word do is a reserved word in both bash and zsh shells as part of the for/while looping constructs as for word in foo bar; do echo $word;done. So that specific word is not a good choice. Try maybe "go" or "yo" instead. :-)

But there are a few options to make it feel like a normal executable.

  • install it without the filename extension in a directory on the PATH such as /usr/local/bin/yo. Make the first line of the script a shebang line: #!/usr/bin/env node, and make it executable with chmod 755 /usr/local/bin/yo. Reload your shell (hash -r or exec $SHELL) and you should be up and running.
  • Or just use an alias: alias yo="node yo.js".