I have never built a CLI tool in Node.js, but I would like to build one. What's the best way to get started with this?
Hi!
@fibric makes a good suggestion. commander is a good choice for parsing command line arguments. One of the strengths of Node is the ecosystem, so if you do not like commander for the argument-parsing part of your command line client there are many other mature and battle-proven modules: e.g. optimist, nopt and yargs.
I was maintaining npm a few years ago and based on my experiences maintaining a command line tool which runs on node, has traction and is doing everything to make the user successful I wrote a book: http://theclibook.com/
You don't have to buy the book, there is still a big part which is downloadable for free as preview. I hope that helps. If you have any questions, ping me: https://twitter.com/robinson_k
Checkout - http://vorpal.js.org/ - best one out there! :)
Denny Trebbin
Lead Fullstack Developer. Experimenting with bleeding-edge tech. Irregularly DJ. Hobby drone pilot. Amateur photographer.
Hi,
I'm using commander.js for CLI tools. It's pretty straight forward.
A little bit of an effort is needed when you plan to write a CLI for an always running background process which should receive commands from a shell.
In this case, you'll spin up Express.js or Koa.js or raw node-http which will listen on a predefined port for commands. Then you are writing a CLI app which talks via http to that specific port.
Additionally, to commander.js, I suggest some colorings like https://github.com/bucaran/clor