interactive-script
Need to write a simple interactive terminal script in node? Dealing with readline can be overwhelming and result in callback hell.
There's a simpler way that easier to write!
To get started, we need to install a few dependencies:
npm install -g interactive-script async-to-gen minimist
Now let's write myScript.js
:
var interactiveScript = ;var minimist = ;
You're given two functions:
- Print to the screen with
say
. - Prompt and wait for a response with
ask
.
You may have noticed that this script uses an async function which is not yet available out of the box in node.js. However you can install and use async-node to take advantage today.
Let's run this script:
$> async-node myScript.js --pirateAvast, me hearty!Whats ye name? LeeHI THERE: LEE$>
Tastes great with:
minimist: Read the arguments provided to your script from the terminal.
colors: Ask and say things in a rainbow of colors for better legibility.