This symbol is not supported.
Instances of repl.REPLServer are created using the start method
or directly using the JavaScript new keyword.
import repl from 'node:repl';
const options = { useColors: true };
const firstInstance = repl.start(options);
const secondInstance = new repl.REPLServer(options);
Constructors Jump to heading
Jump to headingREPLServer()NOTE: According to the documentation:
Instances of
repl.REPLServerare created using therepl.start()method and should not be created directly using the JavaScriptnewkeyword.
REPLServer cannot be subclassed due to implementation specifics in NodeJS.
Properties Jump to heading
Jump to headingcommands: ReadOnlyDict<REPLCommand>The commands registered via replServer.defineCommand().
Jump to headingcompleter: Completer | AsyncCompleterSpecified in the REPL options, this is the function to use for custom Tab auto-completion.
Jump to headingcontext: ContextThe vm.Context provided to the eval function to be used for JavaScript
evaluation.
Jump to headingeditorMode: booleanA value indicating whether the REPL is currently in "editor mode".
Jump to headingeval: REPLEvalSpecified 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.
Jump to headingignoreUndefined: booleanSpecified 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.
Jump to headinginput: ReadableStreamThe Readable stream from which REPL input will be read.
Jump to headinginputStream: ReadableStreamJump to headinglast: anyThe last evaluation result from the REPL (assigned to the _ variable inside of the REPL).
Jump to headinglastError: anyThe last error raised inside the REPL (assigned to the _error variable inside of the REPL).
Jump to headingoutput: WritableStreamThe Writable stream to which REPL output will be written.
Jump to headingoutputStream: WritableStreamSpecified 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'.
Jump to headingunderscoreAssigned: booleanA value indicating whether the _ variable has been assigned.
Jump to headingunderscoreErrAssigned: booleanA value indicating whether the _error variable has been assigned.
Jump to headinguseColors: booleanSpecified in the REPL options, this is a value indicating whether the default
writer function should include ANSI color styling to REPL output.
Jump to headinguseGlobal: booleanSpecified 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.
Jump to headingwriter: REPLWriterSpecified 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.
Methods Jump to heading
Jump to headingaddListener(event: string,listener: (...args: any[]) => void,): thisevents.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
Jump to headingaddListener(event: "close",listener: () => void,): thisJump to headingaddListener(event: "line",listener: (input: string) => void,): thisJump to headingaddListener(event: "pause",listener: () => void,): thisJump to headingaddListener(event: "resume",listener: () => void,): thisJump to headingaddListener(event: "SIGCONT",listener: () => void,): thisJump to headingaddListener(event: "SIGINT",listener: () => void,): thisJump to headingaddListener(event: "SIGTSTP",listener: () => void,): thisJump to headingaddListener(event: "exit",listener: () => void,): thisJump to headingaddListener(event: "reset",listener: (context: Context) => void,): thisThe replServer.clearBufferedCommand() method 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.
Jump to headingdefineCommand(keyword: string,cmd: REPLCommandAction | REPLCommand,): voidThe replServer.defineCommand() method is used to add new .-prefixed commands
to the REPL instance. Such commands are invoked by typing a . followed by the keyword. The cmd is either a Function or an Object with the following
properties:
The following example shows two new commands added to the REPL instance:
import repl from 'node:repl';
const replServer = repl.start({ prompt: '> ' });
replServer.defineCommand('sayhello', {
help: 'Say hello',
action(name) {
this.clearBufferedCommand();
console.log(`Hello, ${name}!`);
this.displayPrompt();
},
});
replServer.defineCommand('saybye', function saybye() {
console.log('Goodbye!');
this.close();
});
The new commands can then be used from within the REPL instance:
> .sayhello Node.js User
Hello, Node.js User!
> .saybye
Goodbye!
Jump to headingdisplayPrompt(preserveCursor?: boolean): voidThe replServer.displayPrompt() method 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'.
When preserveCursor is true, the cursor placement will not be reset to 0.
The replServer.displayPrompt method is primarily intended to be called from
within the action function for commands registered using the replServer.defineCommand() method.
Jump to headingemit(event: string | symbol,...args: any[],): booleanJump to headingemit(event: "close"): booleanJump to headingemit(event: "line",input: string,): booleanJump to headingemit(event: "pause"): booleanJump to headingemit(event: "resume"): booleanJump to headingemit(event: "SIGCONT"): booleanJump to headingemit(event: "SIGINT"): booleanJump to headingemit(event: "SIGTSTP"): booleanJump to headingemit(event: "exit"): booleanJump to headingemit(event: "reset",context: Context,): booleanJump to headingon(event: string,listener: (...args: any[]) => void,): thisJump to headingon(event: "close",listener: () => void,): thisJump to headingon(event: "line",listener: (input: string) => void,): thisJump to headingon(event: "pause",listener: () => void,): thisJump to headingon(event: "resume",listener: () => void,): thisJump to headingon(event: "SIGCONT",listener: () => void,): thisJump to headingon(event: "SIGINT",listener: () => void,): thisJump to headingon(event: "SIGTSTP",listener: () => void,): thisJump to headingon(event: "exit",listener: () => void,): thisJump to headingon(event: "reset",listener: (context: Context) => void,): thisJump to headingonce(event: string,listener: (...args: any[]) => void,): thisJump to headingonce(event: "close",listener: () => void,): thisJump to headingonce(event: "line",listener: (input: string) => void,): thisJump to headingonce(event: "pause",listener: () => void,): thisJump to headingonce(event: "resume",listener: () => void,): thisJump to headingonce(event: "SIGCONT",listener: () => void,): thisJump to headingonce(event: "SIGINT",listener: () => void,): thisJump to headingonce(event: "SIGTSTP",listener: () => void,): thisJump to headingonce(event: "exit",listener: () => void,): thisJump to headingonce(event: "reset",listener: (context: Context) => void,): thisJump to headingprependListener(event: string,listener: (...args: any[]) => void,): thisJump to headingprependListener(event: "close",listener: () => void,): thisJump to headingprependListener(event: "line",listener: (input: string) => void,): thisJump to headingprependListener(event: "pause",listener: () => void,): thisJump to headingprependListener(event: "resume",listener: () => void,): thisJump to headingprependListener(event: "SIGCONT",listener: () => void,): thisJump to headingprependListener(event: "SIGINT",listener: () => void,): thisJump to headingprependListener(event: "SIGTSTP",listener: () => void,): thisJump to headingprependListener(event: "exit",listener: () => void,): thisJump to headingprependListener(event: "reset",listener: (context: Context) => void,): thisJump to headingprependOnceListener(event: string,listener: (...args: any[]) => void,): thisJump to headingprependOnceListener(event: "close",listener: () => void,): thisJump to headingprependOnceListener(event: "line",listener: (input: string) => void,): thisJump to headingprependOnceListener(event: "pause",listener: () => void,): thisJump to headingprependOnceListener(event: "resume",listener: () => void,): thisJump to headingprependOnceListener(event: "SIGCONT",listener: () => void,): thisJump to headingprependOnceListener(event: "SIGINT",listener: () => void,): thisJump to headingprependOnceListener(event: "SIGTSTP",listener: () => void,): thisJump to headingprependOnceListener(event: "exit",listener: () => void,): thisJump to headingprependOnceListener(event: "reset",listener: (context: Context) => void,): thisJump to headingsetupHistory(path: string,callback: (err: Error | null,repl: this,) => void,): voidInitializes 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.