Nodejs library / module for developing interactive CLI apps?

been googling for this and searching stackoverflow, but am not coming across anything. I want to develop an interactive shell with node, and wondering on the best approach for this. Is there a library that anyone could recommend to use?

I have written a library, and now want a CLI interface to interact with it, by 2 methods: running the app with parameters, or via interactive shell. e.g.

$ node myapp doSomething
App Result: I did something
$ node myapp cli
Entering interactive mode...
myapp>
myapp> doSomething
App Result: I did something
myapp>

Any suggestions?

I guess commander.js is what you are looking for.

https://github.com/visionmedia/commander.js

http://oscar-mejia.com/blog/how-to-create-a-command-line-program-with-nodejs/

Also have a look at REPL http://nodejs.org/api/repl.html

I've recently started a project for an enhanced REPL that provides plugins and multi-language support (like CoffeeScript):

http://danielgtaylor.github.com/nesh/

It might be useful for you when building interactive apps. Let me know if you'd like to see any features in Nesh!

This question is a bit old, but I've given some mileage to a module I built a while ago that will launch an interactive shell-like command prompt:

https://github.com/mrvisser/node-readcommand

The key difference to this over something like commander is it allows you to maintain shell session state and accept the commands internally in Node.js, as opposed to requiring every invocation to be a stateless re-run with the shell's parsed arguments. It effectively wraps node's internal readline module to provide:

  • shell-like parsing of the input
  • multi-line command support by escaping the new-line or quoting over it
  • command history support (when using readcommand.loop)
  • argument-based auto-complete (wrapped around readlines text-based auto-complete support

Hoping someone else finds it useful, too.

For a more advanced and opinionated interactive CLI framework, I also built node-corporal: https://github.com/mrvisser/node-corporal . Which is probably more than you're looking for, but it provides a structure and environment for whipping together CLI apps.