Shebang, Shebang!

#!/usr/bin/env node

Adding a shebang to the top of your node script informs the operating system how to execute the file, which in this case, is node.

/usr/bin/env is specifically thought of for cross-platform solutions.

env executes utility after modifying the environment as specified on the command line. The option name=value specifies an environmental variable, name, with a value of value. The option `-i’ causes env to completely ignore the environment it inherits.

###So how do you use it?

Easy. Just declare the shebang at the top of your script.

// index.js

#!/usr/bin/env node

var fs = require('fs');
var str = "> Who let the dogs out?! Who, Who, Who, Who?!";
fs.writeFileSync('output.md', str);

Now you can run the script as:

$ ./index.js

You just saved yourself typing 4 characters! Take the rest of the day off.

###Permission denied

$ permission denied: ./index.js

So you’re getting this because you need to make index.js executable.

$ chmod +x index.js