4 ms·
I have never come across a NodeJS script instead of a shell script. Can you suggest an example to look at that shows the advantages of this?
by mongol 6y ago
I have never come across a NodeJS script instead of a shell script. Can you suggest an example to look at that shows the advantages of this?
- falafel 6y agoThere are plenty of CLI tools built on Node: https://github.com/sindresorhus/awesome-nodejs#command-line-apps https://github.com/sindresorhus/awesome-nodejs#command-line-...
- russellbeattie 6y agoHere's a JS script [1] I wrote a little while ago just for my own use that queries the CDC for the latest virus numbers, then calcs the average, formats the data and prints to the command line. You can pass in a number of days, otherwise it pulls the last 14 days. $ node query-cdc.js 7 It's nothing special, but I wouldn't want to try to do this with command line utilities. (And yes, it was a bit uglier, but I cleaned it up of random crap I had thrown in before posting it.) 1. https://gist.github.com/russellbeattie/f9edf91115b43d6d7ca3cf0b4f9eb060 https://gist.github.com/russellbeattie/f9edf91115b43d6d7ca3c...
- mongol 6y agoThanks, appreciated! I guess using shebang #!/usr/bin/node does not work as # is not a valid comment?
- russellbeattie 6y agoI think Node has an exception for that built in, so you can do that or #!/usr/bin/env node and it'll work.