PREPL
A simple, event-based, programmatic read-eval-print loop
var repl = ; replstart;
Use nc to connect:
$ nc -u prepl.sock
> help
COMMAND DESCRIPTION
help Display this help message
exit Disconnect from REPL
> exit
$
Configuration
Default configuration:
Options
name
: name of the application using prepl. Default:prepl
.socket
: path to the socket to be used. Default:prepl.sock
. See net.Server.listen(path, [callback])address
: IP address to which the net server will bind. Defaultundefined
. See net.Server.listen(port, [host], [backlog], [callback])port
: the TCP port to which the net server will bind. Defaultundefined
. See net.Server.listen(port, [host], [backlog], [callback])
API
Prepl
Exposed by require('prepl')
.
Prepl()
Creates a new Prepl
. Works with and without new
:
var prepl = ; // orvar Prepl = ;var repl = ;
Prepl(options:Object)
Optionally, the first argument of the Server constructor may be an options object to be passed to Prepl.configure.
Prepl.configure(options:Object)
- options
Object
A hash of options to override defaults
Configure the REPL:
repl;
Prepl.register(commands:Array)
- commands
Array
An array of commands to be registered
Registers the list of commands with the REPL. Command have a name identifier, a message to describe the command in the help menu, and a function to carry out the given command. This function is passed the socket object of the client connection to allow output to the client terminal. names may not exceed 15 characters.
var server = foo:'bar'; repl
The command(s) will be now available and listed in the help menu.
> help
COMMAND DESCRIPTION
help Display this help message
exit Disconnect from REPL
start Start the application
restart Restart the application
>
Prepl.unregister(name:String)
- name
String
command to be unregistered
Unregister the given action:
repl;
The command will no longer be available or listen in the help menu:
> help
COMMAND DESCRIPTION
help Display this help message
exit Disconnect from REPL
restart Restart the application
>
Prepl.start(done:Function)
- done
Function
Optional callback to be called when REPL has started
Start the REPL:
replstart { console;}
Prepl.stop(done:Function)
- done
Function
Optional callback to be called when REPL has stopped
Stop the REPL:
repl
Events
Event: 'starting'
Emitted before the REPL server starts:
repl;
Event: 'stopping'
Emitted before the REPL server stops:
repl;
Event: 'stopped'
Emitted once the REPL server has stopped:
repl;
Event: 'ready'
Emitted once the REPL server is ready:
repl;