M
repl.start
History
Added in: v0.1.91
v0.1.91
Introduced in: v0.10.0
v0.10.0
The
handleError parameter has been added.v25.9.0
Added the possibility to add/edit/remove multilines while adding a multiline command.
v24.1.0
The multi-line indicator is now "|" instead of "...". Added support for multi-line history. It is now possible to "fix" multi-line commands with syntax errors by visiting the history and editing the command. When visiting the multiline history from an old node version, the multiline structure is not preserved.
v24.0.0
The
preview option is now available.v13.4.0, v12.17.0
The
terminal option now follows the default description in all cases and useColors checks hasColors() if available.v12.0.0
The
REPL_MAGIC_MODE replMode was removed.v10.0.0
The
breakEvalOnSigint option is supported now.v6.3.0
The
options parameter is optional now.v5.8.0
repl.start(options?): repl.REPLServer
Attributes
prompt?:
stringThe input prompt to display. Default:
'> '
(with a trailing space).input?:
stream.ReadableThe
Readable stream from which REPL input will
be read. Default: process.stdin.output?:
stream.WritableThe
Writable stream to which REPL output will
be written. Default: process.stdout.terminal?:
booleanIf
true, specifies that the output should be
treated as a TTY terminal.
Default: checking the value of the isTTY property on the output
stream upon instantiation.eval?:
FunctionThe function to be used when evaluating each given line
of input. Default: an async wrapper for the JavaScript
eval()
function. An eval function can error with repl.Recoverable to indicate
the input was incomplete and prompt for additional lines. See the
custom evaluation functions section for more details.useColors?:
booleanIf
true, specifies that the default writer
function should include ANSI color styling to REPL output. If a custom
writer function is provided then this has no effect. Default: checking
color support on the output stream if the REPL instance's terminal value
is true.useGlobal?:
booleanIf
true, specifies that the default evaluation
function will use the JavaScript global as the context as opposed to
creating a new separate context for the REPL instance. The node CLI REPL
sets this value to true. Default: false.ignoreUndefined?:
booleanIf
true, specifies that the default writer
will not output the return value of a command if it evaluates to
undefined. Default: false.writer?:
FunctionThe function to invoke to format the output of each
command before writing to
output. Default: util.inspect().completer:
FunctionAn optional function used for custom Tab auto
completion. See
readline.InterfaceCompleter for an example.replMode:
symbolA flag that specifies whether the default evaluator
executes all JavaScript commands in strict mode or default (sloppy) mode.
Acceptable values are:
repl.REPL_MODE_SLOPPY:
to evaluate expressions in sloppy mode.
repl.REPL_MODE_STRICT:
to evaluate expressions in strict mode. This is
equivalent to prefacing every repl statement with
'use strict'.breakEvalOnSigint?:
booleanStop evaluating the current piece of code when
SIGINT is received, such as when Ctrl+C is pressed.
This cannot be used
together with a custom eval function. Default: false.preview?:
booleanDefines if the repl prints autocomplete and output
previews or not. Default:
true with the default eval function and
false in case a custom eval function is used. If terminal is falsy, then
there are no previews and the value of preview has no effect.handleError:
FunctionThis function customizes error handling in the REPL.
It receives the thrown exception as its first argument and must return one
of the following values synchronously:
'print':
to print the error to the output stream (default behavior).
'ignore':
to skip all remaining error handling.
'unhandled':
to treat the exception as fully unhandled. In this case,
the error will be passed to process-wide exception handlers, such as
the
'uncaughtException' event.
The 'unhandled' value may or may not be desirable in situations
where the REPLServer instance has been closed, depending on the particular
use case.Returns:
repl.REPLServerThe repl.start() method creates and starts a repl.REPLServer instance.
If options is a string, then it specifies the input prompt:
import repl from 'node:repl'; // a Unix style prompt repl.start('$ ');
const repl = require('node:repl'); // a Unix style prompt repl.start('$ ');