1. Chalk

Chalk is styling for the command line - add cool color and stuff. Chalk

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
const chalk = require('chalk');
const log = console.log;

log(chalk.blue('Hello') + ' World' + chalk.red('!'));

log(chalk.green(
  'I am a green line ' +
  chalk.blue.underline.bold('with a blue substring') +
  ' that becomes green again!'
));


2. Clear

Clear the terminal screen if possible

1
2
var clear = require('clear');
clear();

3. Commander (minimist/nomnom/etc.)

Argv on steroid - basically handle all the needs of of your cli parameters

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
var program = require('commander');

program
  .version('0.1.0')
  .option('-p, --peppers', 'Add peppers')
  .option('-P, --pineapple', 'Add pineapple')
  .option('-b, --bbq-sauce', 'Add bbq sauce')
  .option('-c, --cheese [type]', 'Add the specified type of cheese [marble]', 'marble')
  .parse(process.argv);

console.log('you ordered a pizza with:');
if (program.peppers) console.log('  - peppers');
if (program.pineapple) console.log('  - pineapple');
if (program.bbqSauce) console.log('  - bbq');
console.log('  - %s cheese', program.cheese);

Commander is probably the most popular (at least if measured in Github stars) but it is not the only one around.

minimist is also a widly used argument parser for command line stuff.

Also worth mentioning: yargs the pirate theme parser


clui

Clui is UI for command lines

Draw spinners, progress bars, etc.

Example:

1
2
3
4
var Sparkline = require('clui').Sparkline;
var reqsPerSec = [10,12,3,7,12,9,23,10,9,19,16,18,12,12];

console.log(Sparkline(reqsPerSec, 'reqs/sec'));

for the following result: result


Figlet

Figlet creates ASCII art from text

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
var figlet = require('figlet');

figlet('Hello World!!', function(err, data) {
    if (err) {
        console.log('Something went wrong...');
        console.dir(err);
        return;
    }
    console.log(data)
});

helloWorldwithFiglet


inquirer

inquirer Handle user interaction:

  • asking questions
  • parsing input
  • validating answers
  • etc.

General structure :

1
2
3
4
5
6
7
8
var inquirer = require('inquirer');
inquirer
  .prompt([
    /* Pass your questions in here */
  ])
  .then(answers => {
    // Use user feedback for... whatever!!
  });

Allow you to create some prompts like this one ;

1
2
3
4
5
6
[?] What do you want to do?
> Order a pizza
 Make a reservation
 --------
 Ask opening hours
 Talk to the receptionist

Configstore

Configstore is a configuration manager for your cli.

(It has a companion package [electron-store](https://github.com/sindresorhus/electron-store for Electron apps))

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
const Configstore = require('configstore');
const packageJson = require('./package.json');
 
// Create a Configstore instance
const config = new Configstore(packageJson.name, {foo: 'bar'});
 
console.log(config.get('foo'));
//=> 'bar'
 
config.set('awesome', true);
console.log(config.get('awesome'));
//=> true
 
// Use dot-notation to access nested properties
config.set('bar.baz', true);
console.log(config.get('bar'));
//=> {baz: true}
 
config.delete('awesome');
console.log(config.get('awesome'));
//=> undefined