node.js bin/ script module loader


node.js bin/ script module loader

  • Adapters for commander.js and node-optimist
  • Injects common dependencies like this.child_process, this.shelljs, etc.
  • Basic set of long-con console loggers for stdout/stderr/verbose with color

  • CLI scripts that are easier to test without running the executable.
  • Reduce boilerplate.

Executables are reduced to thin loading calls.

var bin = require('impulse-bin').create();'commander'), require('./lib/cli/myproj'));

While the rest is separated into input parsing and input consumption.

  • init() receives a CLI input provider like commander.js or node-optimist for you to configure.
  • run() receives the parsed this.options and this.args from the provider.
exports.init = function(provider) {
  provider.option('-c, --config <dir>', 'Config file');
}; = function() {
  if (!this.shelljs._('test', '-f', this.options.config)) {
    this.stderr('config file not found: %s', this.options.config);
  this.stdout('using config file: %s',;
  // ... 
// bin/myproj'commander'), require('./lib/cli/myproj'), 1, 2, 3);
// lib/cli/myproj.js = function() {
  console.log([]; // [1, 2, 3] 


npm install impulse-bin


npm test