REPLServer
Provides a customizable Read-Eval-Print-Loop (REPL).
Instances of repl.REPLServer
will accept individual lines of user input, evaluate those
according to a user-defined evaluation function, then output the result. Input and output
may be from stdin
and stdout
, respectively, or may be connected to any Node.js stream
.
Instances of repl.REPLServer
support automatic completion of inputs, simplistic Emacs-style
line editing, multi-line inputs, ANSI-styled output, saving and restoring current REPL session
state, error recovery, and customizable evaluation functions.
Instances of repl.REPLServer
are created using the repl.start()
method and should not
be created directly using the JavaScript new
keyword.
- See also
Value members
Concrete methods
events.EventEmitter
events.EventEmitter
- close - inherited from
readline.Interface
- line - inherited from
readline.Interface
- pause - inherited from
readline.Interface
- resume - inherited from
readline.Interface
- SIGCONT - inherited from
readline.Interface
- SIGINT - inherited from
readline.Interface
- SIGTSTP - inherited from
readline.Interface
- exit
- reset
Clears any command that has been buffered but not yet executed.
Clears any command that has been buffered but not yet executed.
This method is primarily intended to be called from within the action function for
commands registered using the replServer.defineCommand()
method.
- Since
v9.0.0
Used to add new .
-prefixed commands to the REPL instance. Such commands are invoked
by typing a .
followed by the keyword
.
Used to add new .
-prefixed commands to the REPL instance. Such commands are invoked
by typing a .
followed by the keyword
.
- Value Params
- cmd
The function to invoke when the command is processed.
- keyword
The command keyword (without a leading
.
character).
- See also
Readies the REPL instance for input from the user, printing the configured prompt
to a
new line in the output
and resuming the input
to accept new input.
Readies the REPL instance for input from the user, printing the configured prompt
to a
new line in the output
and resuming the input
to accept new input.
When multi-line input is being entered, an ellipsis is printed rather than the 'prompt'.
This method is primarily intended to be called from within the action function for
commands registered using the replServer.defineCommand()
method.
- Value Params
- preserveCursor
When
true
, the cursor placement will not be reset to0
.
Specified in the REPL options, this is the function to be used when evaluating each
given line of input. If not specified in the REPL options, this is an async wrapper
for the JavaScript eval()
function.
Specified in the REPL options, this is the function to be used when evaluating each
given line of input. If not specified in the REPL options, this is an async wrapper
for the JavaScript eval()
function.
Initializes a history log file for the REPL instance. When executing the Node.js binary and using the command line REPL, a history file is initialized by default. However, this is not the case when creating a REPL programmatically. Use this method to initialize a history log file when working with REPL instances programmatically.
Initializes a history log file for the REPL instance. When executing the Node.js binary and using the command line REPL, a history file is initialized by default. However, this is not the case when creating a REPL programmatically. Use this method to initialize a history log file when working with REPL instances programmatically.
- Value Params
- path
The path to the history file
Specified in the REPL options, this is the function to invoke to format the output of
each command before writing to outputStream
. If not specified in the REPL options,
this will be a wrapper for util.inspect
.
Specified in the REPL options, this is the function to invoke to format the output of
each command before writing to outputStream
. If not specified in the REPL options,
this will be a wrapper for util.inspect
.
Inherited methods
Concrete fields
The commands registered via replServer.defineCommand()
.
The commands registered via replServer.defineCommand()
.
Specified in the REPL options, this is the function to use for custom Tab auto-completion.
Specified in the REPL options, this is the function to use for custom Tab auto-completion.
The vm.Context
provided to the eval
function to be used for JavaScript
evaluation.
The vm.Context
provided to the eval
function to be used for JavaScript
evaluation.
A value indicating whether the REPL is currently in "editor mode".
A value indicating whether the REPL is currently in "editor mode".
- See also
Specified in the REPL options, this is a value indicating whether the default writer
function should output the result of a command if it evaluates to undefined
.
Specified in the REPL options, this is a value indicating whether the default writer
function should output the result of a command if it evaluates to undefined
.
The Readable
stream from which REPL input will be read.
The Readable
stream from which REPL input will be read.
The last evaluation result from the REPL (assigned to the _
variable inside of the REPL).
The last evaluation result from the REPL (assigned to the _
variable inside of the REPL).
- See also
The last error raised inside the REPL (assigned to the _error
variable inside of the REPL).
The last error raised inside the REPL (assigned to the _error
variable inside of the REPL).
- See also
- Since
v9.8.0
The Writable
stream to which REPL output will be written.
The Writable
stream to which REPL output will be written.
Specified in the REPL options, this is a flag that specifies whether the default eval
function should execute all JavaScript commands in strict mode or default (sloppy) mode.
Possible values are:
Specified in the REPL options, this is a flag that specifies whether the default eval
function should execute all JavaScript commands in strict mode or default (sloppy) mode.
Possible values are:
repl.REPL_MODE_SLOPPY
- evaluates expressions in sloppy mode.repl.REPL_MODE_STRICT
- evaluates expressions in strict mode. This is equivalent to prefacing every repl statement with'use strict'
.
A value indicating whether the _
variable has been assigned.
A value indicating whether the _
variable has been assigned.
- See also
A value indicating whether the _error
variable has been assigned.
A value indicating whether the _error
variable has been assigned.
- See also
- Since
v9.8.0
Specified in the REPL options, this is a value indicating whether the default
writer
function should include ANSI color styling to REPL output.
Specified in the REPL options, this is a value indicating whether the default
writer
function should include ANSI color styling to REPL output.
Specified in the REPL options, this is a value indicating whether the default eval
function will use the JavaScript global
as the context as opposed to creating a new
separate context for the REPL instance.
Specified in the REPL options, this is a value indicating whether the default eval
function will use the JavaScript global
as the context as opposed to creating a new
separate context for the REPL instance.