repl8

Automatically generate your REPL commands by writing logic files

npm install repl8
1 downloads in the last week
4 downloads in the last month

REPL8

Create your REPL by slotting REPL files and functionality into your import folder.

Installation

Firstly install the module via npm:

npm install repl8

Then require it into your application:

var repl8 = require('repl8');

We simply call the .start function and pass it in an options object:

repl8.start({
  src: __dirname + '/import', // This is required to tell repl8 where to load in our logic
  ignoreUndefined: true, 
  prompt: 'repl8> '
});

The options object takes the same options as the original nodejs .repl function, with the addition of the src option which points to where we will import our REPL commands. http://nodejs.org/api/repl.html#repl_repl_start_options

Writing Commands

Create a file in your import folder with the name of your command. In this example, we will create one called loop.js

This will immediately give our repl the command loop.

Now inside loop.js, lets make give it some functionality.

module.exports = function (max) {
  for (i = 0; i < max; i++)
  {
    console.log("woo " + i);
  }
}

Now restart our REPL and call our new loop function:

repl8> loop(3)
woo 0
woo 1
woo 2
npm loves you