Expect a filename argument, reads its content and returns it.
I found myself writing the same small boilerplate code over and over:
- expect the first argument to a node script to be a file path
- if so, read it contents and do something with it
// cat.jsvar readit = require'readit';var contents = readit;console.logcontents;
And we use this as such:
$ node cat.jsUsage: /opt/boxen/nvm/v0.8.8/bin/node ./cat.js <file>$ node cat.js dog.jscouldn't read dog.js$ node cat.js cat.js// cat.jsvar readit = require('readit');var fileContents = readit();console.log(contents);