learnyounode
Version:
Learn You The Node.js For Much Win! An intro to Node.js via a set of self-guided workshops.
619 lines (596 loc) • 84.4 kB
HTML
<!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>REPL | Node.js v12.10.0 Documentation</title>
<link rel="stylesheet" href="data:text/css;base64,LyogbGF0aW4tZXh0ICovCkBmb250LWZhY2UgewogIGZvbnQtZmFtaWx5OiAnTGF0byc7CiAgZm9udC1zdHlsZTogaXRhbGljOwogIGZvbnQtd2VpZ2h0OiA0MDA7CiAgc3JjOiBsb2NhbCgnTGF0byBJdGFsaWMnKSwgbG9jYWwoJ0xhdG8tSXRhbGljJyksIHVybChodHRwczovL2ZvbnRzLmdzdGF0aWMuY29tL3MvbGF0by92MTYvUzZ1OHc0Qk1VVFBIanhzQVVpLXFOaVhnN2VVMC53b2ZmMikgZm9ybWF0KCd3b2ZmMicpOwogIHVuaWNvZGUtcmFuZ2U6IFUrMDEwMC0wMjRGLCBVKzAyNTksIFUrMUUwMC0xRUZGLCBVKzIwMjAsIFUrMjBBMC0yMEFCLCBVKzIwQUQtMjBDRiwgVSsyMTEzLCBVKzJDNjAtMkM3RiwgVStBNzIwLUE3RkY7Cn0KLyogbGF0aW4gKi8KQGZvbnQtZmFjZSB7CiAgZm9udC1mYW1pbHk6ICdMYXRvJzsKICBmb250LXN0eWxlOiBpdGFsaWM7CiAgZm9udC13ZWlnaHQ6IDQwMDsKICBzcmM6IGxvY2FsKCdMYXRvIEl0YWxpYycpLCBsb2NhbCgnTGF0by1JdGFsaWMnKSwgdXJsKGh0dHBzOi8vZm9udHMuZ3N0YXRpYy5jb20vcy9sYXRvL3YxNi9TNnU4dzRCTVVUUEhqeHNBWEMtcU5pWGc3US53b2ZmMikgZm9ybWF0KCd3b2ZmMicpOwogIHVuaWNvZGUtcmFuZ2U6IFUrMDAwMC0wMEZGLCBVKzAxMzEsIFUrMDE1Mi0wMTUzLCBVKzAyQkItMDJCQywgVSswMkM2LCBVK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9jb21tZW50IHsKICBjb2xvcjogIzY2NjsKICBmb250LXdlaWdodDogbGlnaHRlcjsKfQo=">
<link rel="canonical" href="https://nodejs.org/api/repl.html">
</head>
<body class="alt apidoc" id="api-section-repl">
<div id="content" class="clearfix">
<div id="column2" class="interior">
<div id="intro" class="interior">
<a href="https://nodejs.org/" title="Go back to the home page">
Node.js
</a>
</div>
<ul>
<li><a href="https://nodejs.org/api/documentation.html" class="nav-documentation">About these Docs</a></li>
<li><a href="https://nodejs.org/api/synopsis.html" class="nav-synopsis">Usage & Example</a></li>
</ul>
<div class="line"></div>
<ul>
<li><a href="https://nodejs.org/api/assert.html" class="nav-assert">Assertion Testing</a></li>
<li><a href="https://nodejs.org/api/async_hooks.html" class="nav-async_hooks">Async Hooks</a></li>
<li><a href="https://nodejs.org/api/buffer.html" class="nav-buffer">Buffer</a></li>
<li><a href="https://nodejs.org/api/addons.html" class="nav-addons">C++ Addons</a></li>
<li><a href="https://nodejs.org/api/n-api.html" class="nav-n-api">C/C++ Addons - N-API</a></li>
<li><a href="https://nodejs.org/api/child_process.html" class="nav-child_process">Child Processes</a></li>
<li><a href="https://nodejs.org/api/cluster.html" class="nav-cluster">Cluster</a></li>
<li><a href="https://nodejs.org/api/cli.html" class="nav-cli">Command Line Options</a></li>
<li><a href="https://nodejs.org/api/console.html" class="nav-console">Console</a></li>
<li><a href="https://nodejs.org/api/crypto.html" class="nav-crypto">Crypto</a></li>
<li><a href="https://nodejs.org/api/debugger.html" class="nav-debugger">Debugger</a></li>
<li><a href="https://nodejs.org/api/deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
<li><a href="https://nodejs.org/api/dns.html" class="nav-dns">DNS</a></li>
<li><a href="https://nodejs.org/api/domain.html" class="nav-domain">Domain</a></li>
<li><a href="https://nodejs.org/api/esm.html" class="nav-esm">ECMAScript Modules</a></li>
<li><a href="https://nodejs.org/api/errors.html" class="nav-errors">Errors</a></li>
<li><a href="https://nodejs.org/api/events.html" class="nav-events">Events</a></li>
<li><a href="https://nodejs.org/api/fs.html" class="nav-fs">File System</a></li>
<li><a href="https://nodejs.org/api/globals.html" class="nav-globals">Globals</a></li>
<li><a href="https://nodejs.org/api/http.html" class="nav-http">HTTP</a></li>
<li><a href="https://nodejs.org/api/http2.html" class="nav-http2">HTTP/2</a></li>
<li><a href="https://nodejs.org/api/https.html" class="nav-https">HTTPS</a></li>
<li><a href="https://nodejs.org/api/inspector.html" class="nav-inspector">Inspector</a></li>
<li><a href="https://nodejs.org/api/intl.html" class="nav-intl">Internationalization</a></li>
<li><a href="https://nodejs.org/api/modules.html" class="nav-modules">Modules</a></li>
<li><a href="https://nodejs.org/api/net.html" class="nav-net">Net</a></li>
<li><a href="https://nodejs.org/api/os.html" class="nav-os">OS</a></li>
<li><a href="https://nodejs.org/api/path.html" class="nav-path">Path</a></li>
<li><a href="https://nodejs.org/api/perf_hooks.html" class="nav-perf_hooks">Performance Hooks</a></li>
<li><a href="https://nodejs.org/api/policy.html" class="nav-policy">Policies</a></li>
<li><a href="https://nodejs.org/api/process.html" class="nav-process">Process</a></li>
<li><a href="https://nodejs.org/api/punycode.html" class="nav-punycode">Punycode</a></li>
<li><a href="https://nodejs.org/api/querystring.html" class="nav-querystring">Query Strings</a></li>
<li><a href="https://nodejs.org/api/readline.html" class="nav-readline">Readline</a></li>
<li><a href="https://nodejs.org/api/repl.html" class="nav-repl active">REPL</a></li>
<li><a href="https://nodejs.org/api/report.html" class="nav-report">Report</a></li>
<li><a href="https://nodejs.org/api/stream.html" class="nav-stream">Stream</a></li>
<li><a href="https://nodejs.org/api/string_decoder.html" class="nav-string_decoder">String Decoder</a></li>
<li><a href="https://nodejs.org/api/timers.html" class="nav-timers">Timers</a></li>
<li><a href="https://nodejs.org/api/tls.html" class="nav-tls">TLS/SSL</a></li>
<li><a href="https://nodejs.org/api/tracing.html" class="nav-tracing">Trace Events</a></li>
<li><a href="https://nodejs.org/api/tty.html" class="nav-tty">TTY</a></li>
<li><a href="https://nodejs.org/api/dgram.html" class="nav-dgram">UDP/Datagram</a></li>
<li><a href="https://nodejs.org/api/url.html" class="nav-url">URL</a></li>
<li><a href="https://nodejs.org/api/util.html" class="nav-util">Utilities</a></li>
<li><a href="https://nodejs.org/api/v8.html" class="nav-v8">V8</a></li>
<li><a href="https://nodejs.org/api/vm.html" class="nav-vm">VM</a></li>
<li><a href="https://nodejs.org/api/worker_threads.html" class="nav-worker_threads">Worker Threads</a></li>
<li><a href="https://nodejs.org/api/zlib.html" class="nav-zlib">Zlib</a></li>
</ul>
<div class="line"></div>
<ul>
<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">GitHub Repo & Issue Tracker</a></li>
</ul>
</div>
<div id="column1" data-id="repl" class="interior">
<header>
<h1>Node.js v12.10.0 Documentation</h1>
<div id="gtoc">
<ul>
<li>
<a href="https://nodejs.org/api/index.html" name="toc">Index</a>
</li>
<li>
<a href="https://nodejs.org/api/all.html">View on single page</a>
</li>
<li>
<a href="https://nodejs.org/api/repl.json">View as JSON</a>
</li>
<li class="version-picker">
<a href="#">View another version <span>▼</span></a>
<ol class="version-picker"><li><a href="https://nodejs.org/docs/latest-v12.x/api/repl.html">12.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v11.x/api/repl.html">11.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v10.x/api/repl.html">10.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v9.x/api/repl.html">9.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v8.x/api/repl.html">8.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v7.x/api/repl.html">7.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v6.x/api/repl.html">6.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v5.x/api/repl.html">5.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v4.x/api/repl.html">4.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/repl.html">0.12.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/repl.html">0.10.x</a></li></ol>
</li>
<li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/repl.md"><span class="github_icon"><svg height="16" width="16" viewBox="0 0 16.1 16.1" fill="currentColor"><path d="M8 0a8 8 0 0 0-2.5 15.6c.4 0 .5-.2.5-.4v-1.5c-2 .4-2.5-.5-2.7-1 0-.1-.5-.9-.8-1-.3-.2-.7-.6 0-.6.6 0 1 .6 1.2.8.7 1.2 1.9 1 2.4.7 0-.5.2-.9.5-1-1.8-.3-3.7-1-3.7-4 0-.9.3-1.6.8-2.2 0-.2-.3-1 .1-2 0 0 .7-.3 2.2.7a7.4 7.4 0 0 1 4 0c1.5-1 2.2-.8 2.2-.8.5 1.1.2 2 .1 2.1.5.6.8 1.3.8 2.2 0 3-1.9 3.7-3.6 4 .3.2.5.7.5 1.4v2.2c0 .2.1.5.5.4A8 8 0 0 0 16 8a8 8 0 0 0-8-8z"></path></svg></span>Edit on GitHub</a></li>
</ul>
</div>
<hr>
</header>
<div id="toc">
<h2>Table of Contents</h2>
<ul>
<li>
<p><span class="stability_2"><a href="#repl_repl">REPL</a></span></p>
<ul>
<li>
<p><a href="#repl_design_and_features">Design and Features</a></p>
<ul>
<li><a href="#repl_commands_and_special_keys">Commands and Special Keys</a></li>
<li>
<p><a href="#repl_default_evaluation">Default Evaluation</a></p>
<ul>
<li><a href="#repl_javascript_expressions">JavaScript Expressions</a></li>
<li><a href="#repl_global_and_local_scope">Global and Local Scope</a></li>
<li><a href="#repl_accessing_core_node_js_modules">Accessing Core Node.js Modules</a></li>
<li><a href="#repl_global_uncaught_exceptions">Global Uncaught Exceptions</a></li>
<li><a href="#repl_assignment_of_the_underscore_variable">Assignment of the <code>_</code> (underscore) variable</a></li>
<li><a href="#repl_await_keyword"><code>await</code> keyword</a></li>
</ul>
</li>
<li>
<p><a href="#repl_custom_evaluation_functions">Custom Evaluation Functions</a></p>
<ul>
<li><a href="#repl_recoverable_errors">Recoverable Errors</a></li>
</ul>
</li>
<li><a href="#repl_customizing_repl_output">Customizing REPL Output</a></li>
</ul>
</li>
<li>
<p><a href="#repl_class_replserver">Class: REPLServer</a></p>
<ul>
<li><a href="#repl_event_exit">Event: 'exit'</a></li>
<li><a href="#repl_event_reset">Event: 'reset'</a></li>
<li><a href="#repl_replserver_definecommand_keyword_cmd">replServer.defineCommand(keyword, cmd)</a></li>
<li><a href="#repl_replserver_displayprompt_preservecursor">replServer.displayPrompt([preserveCursor])</a></li>
<li><a href="#repl_replserver_clearbufferedcommand">replServer.clearBufferedCommand()</a></li>
<li><span class="stability_0"><a href="#repl_replserver_parsereplkeyword_keyword_rest">replServer.parseREPLKeyword(keyword[, rest])</a></span></li>
<li><a href="#repl_replserver_setuphistory_historypath_callback">replServer.setupHistory(historyPath, callback)</a></li>
</ul>
</li>
<li><a href="#repl_repl_start_options">repl.start([options])</a></li>
<li>
<p><a href="#repl_the_node_js_repl">The Node.js REPL</a></p>
<ul>
<li><a href="#repl_environment_variable_options">Environment Variable Options</a></li>
<li><a href="#repl_persistent_history">Persistent History</a></li>
<li><a href="#repl_using_the_node_js_repl_with_advanced_line_editors">Using the Node.js REPL with advanced line-editors</a></li>
<li><a href="#repl_starting_multiple_repl_instances_against_a_single_running_instance">Starting multiple REPL instances against a single running instance</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div id="apicontent">
<h1>REPL<span><a class="mark" href="#repl_repl" id="repl_repl">#</a></span></h1>
<p></p><div class="api_stability api_stability_2"><a href="https://nodejs.org/api/documentation.html#documentation_stability_index">Stability: 2</a> - Stable</div><p></p>
<p>The <code>repl</code> module provides a Read-Eval-Print-Loop (REPL) implementation that
is available both as a standalone program or includible in other applications.
It can be accessed using:</p>
<pre><code class="language-js">const repl = require('repl');
</code></pre>
<h2>Design and Features<span><a class="mark" href="#repl_design_and_features" id="repl_design_and_features">#</a></span></h2>
<p>The <code>repl</code> module exports the <a href="#repl_class_replserver"><code>repl.REPLServer</code></a> class. While running,
instances of <a href="#repl_class_replserver"><code>repl.REPLServer</code></a> 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 <code>stdin</code> and <code>stdout</code>, respectively, or may
be connected to any Node.js <a href="https://nodejs.org/api/stream.html">stream</a>.</p>
<p>Instances of <a href="#repl_class_replserver"><code>repl.REPLServer</code></a> 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.</p>
<h3>Commands and Special Keys<span><a class="mark" href="#repl_commands_and_special_keys" id="repl_commands_and_special_keys">#</a></span></h3>
<p>The following special commands are supported by all REPL instances:</p>
<ul>
<li><code>.break</code> - When in the process of inputting a multi-line expression, entering
the <code>.break</code> command (or pressing the <code><ctrl>-C</code> key combination) will abort
further input or processing of that expression.</li>
<li><code>.clear</code> - Resets the REPL <code>context</code> to an empty object and clears any
multi-line expression currently being input.</li>
<li><code>.exit</code> - Close the I/O stream, causing the REPL to exit.</li>
<li><code>.help</code> - Show this list of special commands.</li>
<li><code>.save</code> - Save the current REPL session to a file:
<code>> .save ./file/to/save.js</code></li>
<li><code>.load</code> - Load a file into the current REPL session.
<code>> .load ./file/to/load.js</code></li>
<li><code>.editor</code> - Enter editor mode (<code><ctrl>-D</code> to finish, <code><ctrl>-C</code> to cancel).</li>
</ul>
<pre><code class="language-console">> .editor
// Entering editor mode (^D to finish, ^C to cancel)
function welcome(name) {
return `Hello ${name}!`;
}
welcome('Node.js User');
// ^D
'Hello Node.js User!'
>
</code></pre>
<p>The following key combinations in the REPL have these special effects:</p>
<ul>
<li><code><ctrl>-C</code> - When pressed once, has the same effect as the <code>.break</code> command.
When pressed twice on a blank line, has the same effect as the <code>.exit</code>
command.</li>
<li><code><ctrl>-D</code> - Has the same effect as the <code>.exit</code> command.</li>
<li><code><tab></code> - When pressed on a blank line, displays global and local (scope)
variables. When pressed while entering other input, displays relevant
autocompletion options.</li>
</ul>
<h3>Default Evaluation<span><a class="mark" href="#repl_default_evaluation" id="repl_default_evaluation">#</a></span></h3>
<p>By default, all instances of <a href="#repl_class_replserver"><code>repl.REPLServer</code></a> use an evaluation function
that evaluates JavaScript expressions and provides access to Node.js' built-in
modules. This default behavior can be overridden by passing in an alternative
evaluation function when the <a href="#repl_class_replserver"><code>repl.REPLServer</code></a> instance is created.</p>
<h4>JavaScript Expressions<span><a class="mark" href="#repl_javascript_expressions" id="repl_javascript_expressions">#</a></span></h4>
<p>The default evaluator supports direct evaluation of JavaScript expressions:</p>
<pre><code class="language-console">> 1 + 1
2
> const m = 2
undefined
> m + 1
3
</code></pre>
<p>Unless otherwise scoped within blocks or functions, variables declared
either implicitly or using the <code>const</code>, <code>let</code>, or <code>var</code> keywords
are declared at the global scope.</p>
<h4>Global and Local Scope<span><a class="mark" href="#repl_global_and_local_scope" id="repl_global_and_local_scope">#</a></span></h4>
<p>The default evaluator provides access to any variables that exist in the global
scope. It is possible to expose a variable to the REPL explicitly by assigning
it to the <code>context</code> object associated with each <code>REPLServer</code>:</p>
<pre><code class="language-js">const repl = require('repl');
const msg = 'message';
repl.start('> ').context.m = msg;
</code></pre>
<p>Properties in the <code>context</code> object appear as local within the REPL:</p>
<pre><code class="language-console">$ node repl_test.js
> m
'message'
</code></pre>
<p>Context properties are not read-only by default. To specify read-only globals,
context properties must be defined using <code>Object.defineProperty()</code>:</p>
<pre><code class="language-js">const repl = require('repl');
const msg = 'message';
const r = repl.start('> ');
Object.defineProperty(r.context, 'm', {
configurable: false,
enumerable: true,
value: msg
});
</code></pre>
<h4>Accessing Core Node.js Modules<span><a class="mark" href="#repl_accessing_core_node_js_modules" id="repl_accessing_core_node_js_modules">#</a></span></h4>
<p>The default evaluator will automatically load Node.js core modules into the
REPL environment when used. For instance, unless otherwise declared as a
global or scoped variable, the input <code>fs</code> will be evaluated on-demand as
<code>global.fs = require('fs')</code>.</p>
<pre><code class="language-console">> fs.createReadStream('./some/file');
</code></pre>
<h4>Global Uncaught Exceptions<span><a class="mark" href="#repl_global_uncaught_exceptions" id="repl_global_uncaught_exceptions">#</a></span></h4>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v12.3.0</td>
<td><p>The <code>'uncaughtException'</code> event is from now on triggered if the repl is used as standalone program.</p></td></tr>
</tbody></table>
</details>
</div>
<p>The REPL uses the <a href="https://nodejs.org/api/domain.html"><code>domain</code></a> module to catch all uncaught exceptions for that
REPL session.</p>
<p>This use of the <a href="https://nodejs.org/api/domain.html"><code>domain</code></a> module in the REPL has these side effects:</p>
<ul>
<li>Uncaught exceptions only emit the <a href="https://nodejs.org/api/process.html#process_event_uncaughtexception"><code>'uncaughtException'</code></a> event if the
<code>repl</code> is used as standalone program. If the <code>repl</code> is included anywhere in
another application, adding a listener for this event will throw an
<a href="https://nodejs.org/api/errors.html#errors_err_invalid_repl_input"><code>ERR_INVALID_REPL_INPUT</code></a> exception.</li>
<li>Trying to use <a href="https://nodejs.org/api/process.html#process_process_setuncaughtexceptioncapturecallback_fn"><code>process.setUncaughtExceptionCaptureCallback()</code></a> throws
an <a href="https://nodejs.org/api/errors.html#errors_err_domain_cannot_set_uncaught_exception_capture"><code>ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE</code></a> error.</li>
</ul>
<p>As standalone program:</p>
<pre><code class="language-js">process.on('uncaughtException', () => console.log('Uncaught'));
throw new Error('foobar');
// Uncaught
</code></pre>
<p>When used in another application:</p>
<pre><code class="language-js">process.on('uncaughtException', () => console.log('Uncaught'));
// TypeError [ERR_INVALID_REPL_INPUT]: Listeners for `uncaughtException`
// cannot be used in the REPL
throw new Error('foobar');
// Thrown:
// Error: foobar
</code></pre>
<h4>Assignment of the <code>_</code> (underscore) variable<span><a class="mark" href="#repl_assignment_of_the_underscore_variable" id="repl_assignment_of_the_underscore_variable">#</a></span></h4>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.8.0</td>
<td><p>Added <code>_error</code> support.</p></td></tr>
</tbody></table>
</details>
</div>
<p>The default evaluator will, by default, assign the result of the most recently
evaluated expression to the special variable <code>_</code> (underscore).
Explicitly setting <code>_</code> to a value will disable this behavior.</p>
<pre><code class="language-console">> [ 'a', 'b', 'c' ]
[ 'a', 'b', 'c' ]
> _.length
3
> _ += 1
Expression assignment to _ now disabled.
4
> 1 + 1
2
> _
4
</code></pre>
<p>Similarly, <code>_error</code> will refer to the last seen error, if there was any.
Explicitly setting <code>_error</code> to a value will disable this behavior.</p>
<pre><code class="language-console">> throw new Error('foo');
Error: foo
> _error.message
'foo'
</code></pre>
<h4><code>await</code> keyword<span><a class="mark" href="#repl_await_keyword" id="repl_await_keyword">#</a></span></h4>
<p>With the <a href="https://nodejs.org/api/cli.html#cli_experimental_repl_await"><code>--experimental-repl-await</code></a> command line option specified,
experimental support for the <code>await</code> keyword is enabled.</p>
<pre><code class="language-console">> await Promise.resolve(123)
123
> await Promise.reject(new Error('REPL await'))
Error: REPL await
at repl:1:45
> const timeout = util.promisify(setTimeout);
undefined
> const old = Date.now(); await timeout(1000); console.log(Date.now() - old);
1002
undefined
</code></pre>
<h3>Custom Evaluation Functions<span><a class="mark" href="#repl_custom_evaluation_functions" id="repl_custom_evaluation_functions">#</a></span></h3>
<p>When a new <a href="#repl_class_replserver"><code>repl.REPLServer</code></a> is created, a custom evaluation function may be
provided. This can be used, for instance, to implement fully customized REPL
applications.</p>
<p>The following illustrates a hypothetical example of a REPL that performs
translation of text from one language to another:</p>
<pre><code class="language-js">const repl = require('repl');
const { Translator } = require('translator');
const myTranslator = new Translator('en', 'fr');
function myEval(cmd, context, filename, callback) {
callback(null, myTranslator.translate(cmd));
}
repl.start({ prompt: '> ', eval: myEval });
</code></pre>
<h4>Recoverable Errors<span><a class="mark" href="#repl_recoverable_errors" id="repl_recoverable_errors">#</a></span></h4>
<p>As a user is typing input into the REPL prompt, pressing the <code><enter></code> key will
send the current line of input to the <code>eval</code> function. In order to support
multi-line input, the eval function can return an instance of <code>repl.Recoverable</code>
to the provided callback function:</p>
<pre><code class="language-js">function myEval(cmd, context, filename, callback) {
let result;
try {
result = vm.runInThisContext(cmd);
} catch (e) {
if (isRecoverableError(e)) {
return callback(new repl.Recoverable(e));
}
}
callback(null, result);
}
function isRecoverableError(error) {
if (error.name === 'SyntaxError') {
return /^(Unexpected end of input|Unexpected token)/.test(error.message);
}
return false;
}
</code></pre>
<h3>Customizing REPL Output<span><a class="mark" href="#repl_customizing_repl_output" id="repl_customizing_repl_output">#</a></span></h3>
<p>By default, <a href="#repl_class_replserver"><code>repl.REPLServer</code></a> instances format output using the
<a href="https://nodejs.org/api/util.html#util_util_inspect_object_options"><code>util.inspect()</code></a> method before writing the output to the provided <code>Writable</code>
stream (<code>process.stdout</code> by default). The <code>showProxy</code> inspection option is set
to true by default and the <code>colors</code> option is set to true depending on the
REPL's <code>useColors</code> option.</p>
<p>The <code>useColors</code> boolean option can be specified at construction to instruct the
default writer to use ANSI style codes to colorize the output from the
<code>util.inspect()</code> method.</p>
<p>If the REPL is run as standalone program, it is also possible to change the
REPL's <a href="https://nodejs.org/api/util.html#util_util_inspect_object_options">inspection defaults</a> from inside the REPL by using the
<code>inspect.replDefaults</code> property which mirrors the <code>defaultOptions</code> from
<a href="https://nodejs.org/api/util.html#util_util_inspect_object_options"><code>util.inspect()</code></a>.</p>
<pre><code class="language-console">> util.inspect.replDefaults.compact = false;
false
> [1]
[
1
]
>
</code></pre>
<p>To fully customize the output of a <a href="#repl_class_replserver"><code>repl.REPLServer</code></a> instance pass in a new
function for the <code>writer</code> option on construction. The following example, for
instance, simply converts any input text to upper case:</p>
<pre><code class="language-js">const repl = require('repl');
const r = repl.start({ prompt: '> ', eval: myEval, writer: myWriter });
function myEval(cmd, context, filename, callback) {
callback(null, cmd);
}
function myWriter(output) {
return output.toUpperCase();
}
</code></pre>
<h2>Class: REPLServer<span><a class="mark" href="#repl_class_replserver" id="repl_class_replserver">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.1.91</span>
</div>
<ul>
<li>Extends: <a href="https://nodejs.org/api/readline.html#readline_class_interface" class="type"><readline.Interface></a></li>
</ul>
<p>Instances of <code>repl.REPLServer</code> are created using the <code>repl.start()</code> method and
<em>should not</em> be created directly using the JavaScript <code>new</code> keyword.</p>
<h3>Event: 'exit'<span><a class="mark" href="#repl_event_exit" id="repl_event_exit">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.7.7</span>
</div>
<p>The <code>'exit'</code> event is emitted when the REPL is exited either by receiving the
<code>.exit</code> command as input, the user pressing <code><ctrl>-C</code> twice to signal <code>SIGINT</code>,
or by pressing <code><ctrl>-D</code> to signal <code>'end'</code> on the input stream. The listener
callback is invoked without any arguments.</p>
<pre><code class="language-js">replServer.on('exit', () => {
console.log('Received "exit" event from repl!');
process.exit();
});
</code></pre>
<h3>Event: 'reset'<span><a class="mark" href="#repl_event_reset" id="repl_event_reset">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.11.0</span>
</div>
<p>The <code>'reset'</code> event is emitted when the REPL's context is reset. This occurs
whenever the <code>.clear</code> command is received as input <em>unless</em> the REPL is using
the default evaluator and the <code>repl.REPLServer</code> instance was created with the
<code>useGlobal</code> option set to <code>true</code>. The listener callback will be called with a
reference to the <code>context</code> object as the only argument.</p>
<p>This can be used primarily to re-initialize REPL context to some pre-defined
state:</p>
<pre><code class="language-js">const repl = require('repl');
function initializeContext(context) {
context.m = 'test';
}
const r = repl.start({ prompt: '> ' });
initializeContext(r.context);
r.on('reset', initializeContext);
</code></pre>
<p>When this code is executed, the global <code>'m'</code> variable can be modified but then
reset to its initial value using the <code>.clear</code> command:</p>
<pre><code class="language-console">$ ./node example.js
> m
'test'
> m = 1
1
> m
1
> .clear
Clearing context...
> m
'test'
>
</code></pre>
<h3>replServer.defineCommand(keyword, cmd)<span><a class="mark" href="#repl_replserver_definecommand_keyword_cmd" id="repl_replserver_definecommand_keyword_cmd">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.3.0</span>
</div>
<ul>
<li><code>keyword</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> The command keyword (<em>without</em> a leading <code>.</code> character).</li>
<li><code>cmd</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> The function to invoke when the command is processed.</li>
</ul>
<p>The <code>replServer.defineCommand()</code> method is used to add new <code>.</code>-prefixed commands
to the REPL instance. Such commands are invoked by typing a <code>.</code> followed by the
<code>keyword</code>. The <code>cmd</code> is either a <code>Function</code> or an <code>Object</code> with the following
properties:</p>
<ul>
<li><code>help</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Help text to be displayed when <code>.help</code> is entered (Optional).</li>
<li><code>action</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> The function to execute, optionally accepting a single
string argument.</li>
</ul>
<p>The following example shows two new commands added to the REPL instance:</p>
<pre><code class="language-js">const repl = require('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();
});
</code></pre>
<p>The new commands can then be used from within the REPL instance:</p>
<pre><code class="language-txt">> .sayhello Node.js User
Hello, Node.js User!
> .saybye
Goodbye!
</code></pre>
<h3>replServer.displayPrompt([preserveCursor])<span><a class="mark" href="#repl_replserver_displayprompt_preservecursor" id="repl_replserver_displayprompt_preservecursor">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.1.91</span>
</div>
<ul>
<li><code>preserveCursor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>The <code>replServer.displayPrompt()</code> method readies the REPL instance for input
from the user, printing the configured <code>prompt</code> to a new line in the <code>output</code>
and resuming the <code>input</code> to accept new input.</p>
<p>When multi-line input is being entered, an ellipsis is printed rather than the
'prompt'.</p>
<p>When <code>preserveCursor</code> is <code>true</code>, the cursor placement will not be reset to <code>0</code>.</p>
<p>The <code>replServer.displayPrompt</code> method is primarily intended to be called from
within the action function for commands registered using the
<code>replServer.defineCommand()</code> method.</p>
<h3>replServer.clearBufferedCommand()<span><a class="mark" href="#repl_replserver_clearbufferedcommand" id="repl_replserver_clearbufferedcommand">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v9.0.0</span>
</div>
<p>The <code>replServer.clearBufferedCommand()</code> 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
<code>replServer.defineCommand()</code> method.</p>
<h3>replServer.parseREPLKeyword(keyword[, rest])<span><a class="mark" href="#repl_replserver_parsereplkeyword_keyword_rest" id="repl_replserver_parsereplkeyword_keyword_rest">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.8.9</span><span>Deprecated since: v9.0.0</span>
</div>
<ul>
<li><code>keyword</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> the potential keyword to parse and execute</li>
<li><code>rest</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type"><any></a> any parameters to the keyword command</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p></p><div class="api_stability api_stability_0"><a href="https://nodejs.org/api/documentation.html#documentation_stability_index">Stability: 0</a> - Deprecated.</div><p></p>
<p>An internal method used to parse and execute <code>REPLServer</code> keywords.
Returns <code>true</code> if <code>keyword</code> is a valid keyword, otherwise <code>false</code>.</p>
<h3>replServer.setupHistory(historyPath, callback)<span><a class="mark" href="#repl_replserver_setuphistory_historypath_callback" id="repl_replserver_setuphistory_historypath_callback">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v11.10.0</span>
</div>
<ul>
<li><code>historyPath</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> the path to the history file</li>
<li>
<p><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> called when history writes are ready or upon error</p>
<ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li>
<li><code>repl</code> <a href="https://nodejs.org/api/repl.html#repl_class_replserver" class="type"><repl.REPLServer></a></li>
</ul>
</li>
</ul>
<p>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.</p>
<h2>repl.start([options])<a class="srclink" href="https://github.com/nodejs/node/blob/3a2e75d9a5c31d20e429d505b82dd182e33f459a/lib/repl.js#L823">[src]</a><span><a class="mark" href="#repl_repl_start_options" id="repl_repl_start_options">#</a></span></h2>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v12.0.0</td>
<td><p>The <code>terminal</code> option now follows the default description in all cases and <code>useColors</code> checks <code>hasColors()</code> if available.</p></td></tr>
<tr><td>v10.0.0</td>
<td><p>The <code>REPL_MAGIC_MODE</code> <code>replMode</code> was removed.</p></td></tr>
<tr><td>v5.8.0</td>
<td><p>The <code>options</code> parameter is optional now.</p></td></tr>
<tr><td>v0.1.91</td>
<td><p><span>Added in: v0.1.91</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li>
<p><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></p>
<ul>
<li><code>prompt</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> The input prompt to display. <strong>Default:</strong> <code>'> '</code>
(with a trailing space).</li>
<li><code>input</code> <a href="https://nodejs.org/api/stream.html#stream_class_stream_readable" class="type"><stream.Readable></a> The <code>Readable</code> stream from which REPL input will
be read. <strong>Default:</strong> <code>process.stdin</code>.</li>
<li><code>output</code> <a href="https://nodejs.org/api/stream.html#stream_class_stream_writable" class="type"><stream.Writable></a> The <code>Writable</code> stream to which REPL output will
be written. <strong>Default:</strong> <code>process.stdout</code>.</li>
<li><code>terminal</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> If <code>true</code>, sp