Writing interactive command line apps in JavaScript with Node.js, or how to write the most classic type of software on the most modern framework without frying your brain in the process

THE PROBLEM

Say you want to write a little command line application. For example, a simple app that greets you, asks for your name, and then talks to you by your name. Here’s a sample session showing how your intended app looks like when used (user-typed input shown in red):

hello-whats-your-name

But here’s the catch: you want to write this using JavaScript. Maybe JavaScript is your favorite language, or possibly you’re trying to learn it in order to develop web sites. In any case — you start researching, and it seems not-that-easy to use JavaScript outside the web browser. JavaScript was born in and for the web, and it has never felt very at home at the command line. But not all is lost…

Read the rest of this entry »