- Assertion Testing
- Buffer
- C++ Addons
- C/C++ Addons - N-API
- Child Processes
- Cluster
- Command Line Options
- Console
- Crypto
- Debugger
- DNS
- Domain
- Errors
- Events
- File System
- Globals
- HTTP
- HTTPS
- Internationalization
- Modules
- Net
- OS
- Path
- Process
- Punycode
- Query Strings
- Readline
- REPL
- Stream
- String Decoder
- Timers
- TLS/SSL
- TTY
- UDP/Datagram
- URL
- Utilities
- V8
- VM
- ZLIB
Node.js v6.17.1 Documentation
Table of Contents
REPL#
The repl 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:
const repl = require('repl');
Design and Features#
The repl module exports the repl.REPLServer class. While running, 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.
Commands and Special Keys#
The following special commands are supported by all REPL instances:
.break- When in the process of inputting a multi-line expression, entering the.breakcommand (or pressing the<ctrl>-Ckey combination) will abort further input or processing of that expression..clear- Resets the REPLcontextto an empty object and clears any multi-line expression currently being input..exit- Close the I/O stream, causing the REPL to exit..help- Show this list of special commands..save- Save the current REPL session to a file:> .save ./file/to/save.js.load- Load a file into the current REPL session.> .load ./file/to/load.js.editor- Enter editor mode (<ctrl>-Dto finish,<ctrl>-Cto cancel)
> .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!'
>
The following key combinations in the REPL have these special effects:
<ctrl>-C- When pressed once, has the same effect as the.breakcommand. When pressed twice on a blank line, has the same effect as the.exitcommand.<ctrl>-D- Has the same effect as the.exitcommand.<tab>