Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Keep your REPL logic seperate
JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
README.md
index.js
package.json

README.md

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
Something went wrong with that request. Please try again.