11# REPL
22
3+ <!-- introduced_in=v0.10.0-->
4+
35## Stable REPL
46
57> This section documents how to ` node:repl ` module acts without the
68> ` --exprimental-repl ` CLI flag enabled.
79
8- <!-- introduced_in=v0.10.0-->
9-
1010> Stability: 2 - Stable
1111
1212<!-- source_link=lib/internal/repl/stable/index.js -->
@@ -21,15 +21,15 @@ const repl = require('node:repl');
2121
2222### Design and features
2323
24- The ` node:repl ` module exports the [ ` repl.REPLServer ` ] [ 11 ] class. While running,
25- instances of [ ` repl.REPLServer ` ] [ 11 ] will accept individual lines of user input,
24+ The ` node:repl ` module exports the [ ` repl.REPLServer ` ] [ ] class. While running,
25+ instances of [ ` repl.REPLServer ` ] [ ] will accept individual lines of user input,
2626evaluate those according to a user-defined evaluation function, then output the
2727result. Input and output may be from ` stdin ` and ` stdout ` , respectively, or may
28- be connected to any Node.js [ stream] [ 15 ] .
28+ be connected to any Node.js [ stream] [ ] .
2929
30- Instances of [ ` repl.REPLServer ` ] [ 11 ] support automatic completion of inputs,
30+ Instances of [ ` repl.REPLServer ` ] [ ] support automatic completion of inputs,
3131completion preview, simplistic Emacs-style line editing, multi-line inputs,
32- [ ZSH] [ 02 ] -like reverse-i-search, [ ZSH] [ 02 ] -like substring-based history search,
32+ [ ZSH] [ ] -like reverse-i-search, [ ZSH] [ ] -like substring-based history search,
3333ANSI-styled output, saving and restoring current REPL session state, error
3434recovery, and customizable evaluation functions. Terminals that do not support
3535ANSI styles and Emacs-style line editing automatically fall back to a limited
@@ -78,15 +78,15 @@ The following key combinations in the REPL have these special effects:
7878 (scope) variables. When pressed while entering other input, displays relevant
7979 autocompletion options.
8080
81- For key bindings related to the reverse-i-search, see [ ` reverse-i-search ` ] [ 13 ] .
82- For all other key bindings, see [ TTY keybindings] [ 01 ] .
81+ For key bindings related to the reverse-i-search, see [ ` reverse-i-search ` ] [ ] .
82+ For all other key bindings, see [ TTY keybindings] [ ] .
8383
8484#### Default evaluation
8585
86- By default, all instances of [ ` repl.REPLServer ` ] [ 11 ] use an evaluation function
86+ By default, all instances of [ ` repl.REPLServer ` ] [ ] use an evaluation function
8787that evaluates JavaScript expressions and provides access to Node.js built-in
8888modules. This default behavior can be overridden by passing in an alternative
89- evaluation function when the [ ` repl.REPLServer ` ] [ 11 ] instance is created.
89+ evaluation function when the [ ` repl.REPLServer ` ] [ ] instance is created.
9090
9191##### JavaScript expressions
9292
@@ -164,14 +164,14 @@ changes:
164164 repl is used as standalone program.
165165-->
166166
167- The REPL uses the [ ` domain ` ] [ 08 ] module to catch all uncaught exceptions for that
167+ The REPL uses the [ ` domain ` ] [ ] module to catch all uncaught exceptions for that
168168REPL session.
169169
170- This use of the [ ` domain ` ] [ 08 ] module in the REPL has these side effects:
170+ This use of the [ ` domain ` ] [ ] module in the REPL has these side effects:
171171
172- * Uncaught exceptions only emit the [ ` 'uncaughtException' ` ] [ 03 ] event in the
172+ * Uncaught exceptions only emit the [ ` 'uncaughtException' ` ] [ ] event in the
173173 standalone REPL. Adding a listener for this event in a REPL within
174- another Node.js program results in [ ` ERR_INVALID_REPL_INPUT ` ] [ 06 ] .
174+ another Node.js program results in [ ` ERR_INVALID_REPL_INPUT ` ] [ ] .
175175
176176 ``` js
177177 const r = repl .start ();
@@ -184,8 +184,8 @@ This use of the [`domain`][08] module in the REPL has these side effects:
184184 r .close ();
185185 ```
186186
187- * Trying to use [ ` process.setUncaughtExceptionCaptureCallback() ` ] [ 09 ] throws
188- an [ ` ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE ` ] [ 05 ] error.
187+ * Trying to use [ ` process.setUncaughtExceptionCaptureCallback() ` ] [ ] throws
188+ an [ ` ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE ` ] [ ] error.
189189
190190##### Assignment of the ` _ ` (underscore) variable
191191
@@ -258,7 +258,7 @@ undefined
258258234
259259```
260260
261- [ ` --no-experimental-repl-await ` ] [ 04 ] shall disable top-level await in REPL.
261+ [ ` --no-experimental-repl-await ` ] [ ] shall disable top-level await in REPL.
262262
263263#### Reverse-i-search
264264
@@ -268,7 +268,7 @@ added:
268268 - v12.17.0
269269-->
270270
271- The REPL supports bi-directional reverse-i-search similar to [ ZSH] [ 02 ] . It is
271+ The REPL supports bi-directional reverse-i-search similar to [ ZSH] [ ] . It is
272272triggered with <kbd >Ctrl</kbd >+<kbd >R</kbd > to search backward
273273and <kbd >Ctrl</kbd >+<kbd >S</kbd > to search forwards.
274274
@@ -283,7 +283,7 @@ direction from the current position on.
283283
284284#### Custom evaluation functions
285285
286- When a new [ ` repl.REPLServer ` ] [ 11 ] is created, a custom evaluation function may be
286+ When a new [ ` repl.REPLServer ` ] [ ] is created, a custom evaluation function may be
287287provided. This can be used, for instance, to implement fully customized REPL
288288applications.
289289
@@ -332,32 +332,32 @@ function isRecoverableError(error) {
332332
333333#### Customizing REPL output
334334
335- By default, [ ` repl.REPLServer ` ] [ 11 ] instances format output using the
336- [ ` util.inspect() ` ] [ 14 ] method before writing the output to the provided ` Writable `
337- [ stream] [ 15 ] (` process.stdout ` by default). The ` showProxy ` inspection option is set
335+ By default, [ ` repl.REPLServer ` ] [ ] instances format output using the
336+ [ ` util.inspect() ` ] [ ] method before writing the output to the provided ` Writable `
337+ [ stream] [ ] (` process.stdout ` by default). The ` showProxy ` inspection option is set
338338to true by default and the ` colors ` option is set to true depending on the
339339REPL's ` useColors ` option.
340340
341341The ` useColors ` boolean option can be specified at construction to instruct the
342342default writer to use ANSI style codes to colorize the output from the
343- [ ` util.inspect() ` ] [ 14 ] method.
343+ [ ` util.inspect() ` ] [ ] method.
344344
345345If the REPL is run as standalone program, it is also possible to change the
346- REPL's [ inspection defaults] [ 14 ] from inside the REPL by using the
346+ REPL's [ inspection defaults] [ `util.inspect()` ] from inside the REPL by using the
347347` inspect.replDefaults ` property which mirrors the ` defaultOptions ` from
348- [ ` util.inspect() ` ] [ 14 ] .
348+ [ ` util.inspect() ` ] [ ] .
349349
350350``` console
351351> util.inspect.replDefaults.compact = false ;
352352false
353- > [01 ]
353+ > [1 ]
354354[
355355 1
356356]
357357>
358358```
359359
360- To fully customize the output of a [ ` repl.REPLServer ` ] [ 11 ] instance pass in a new
360+ To fully customize the output of a [ ` repl.REPLServer ` ] [ ] instance pass in a new
361361function for the ` writer ` option on construction. The following example, for
362362instance, simply converts any input text to upper case:
363363
@@ -381,10 +381,10 @@ function myWriter(output) {
381381added: v0.1.91
382382-->
383383
384- * ` options ` {Object|string} See [ ` repl.start() ` ] [ 12 ]
384+ * ` options ` {Object|string} See [ ` repl.start() ` ] [ ]
385385* Extends: {readline.Interface}
386386
387- Instances of ` repl.REPLServer ` are created using the [ ` repl.start() ` ] [ 12 ] method
387+ Instances of ` repl.REPLServer ` are created using the [ ` repl.start() ` ] [ ] method
388388or directly using the JavaScript ` new ` keyword.
389389
390390``` js
@@ -612,9 +612,9 @@ changes:
612612* ` options ` {Object|string}
613613 * ` prompt ` {string} The input prompt to display. ** Default:** ` '> ' `
614614 (with a trailing space).
615- * ` input ` {[ stream] [ 15 ] .Readable} The ` Readable ` stream from which REPL input will
615+ * ` input ` {[ stream] [ ] .Readable} The ` Readable ` stream from which REPL input will
616616 be read. ** Default:** ` process.stdin ` .
617- * ` output ` {[ stream] [ 15 ] .Writable} The ` Writable ` stream to which REPL output will
617+ * ` output ` {[ stream] [ ] .Writable} The ` Writable ` stream to which REPL output will
618618 be written. ** Default:** ` process.stdout ` .
619619 * ` terminal ` {boolean} If ` true ` , specifies that the ` output ` should be
620620 treated as a TTY terminal.
@@ -637,9 +637,9 @@ changes:
637637 will not output the return value of a command if it evaluates to
638638 ` undefined ` . ** Default:** ` false ` .
639639 * ` writer ` {Function} The function to invoke to format the output of each
640- command before writing to ` output ` . ** Default:** [ ` util.inspect() ` ] [ 14 ] .
640+ command before writing to ` output ` . ** Default:** [ ` util.inspect() ` ] [ ] .
641641 * ` completer ` {Function} An optional function used for custom Tab auto
642- completion. See [ ` readline.InterfaceCompleter ` ] [ 10 ] for an example.
642+ completion. See [ ` readline.InterfaceCompleter ` ] [ ] for an example.
643643 * ` replMode ` {symbol} A flag that specifies whether the default evaluator
644644 executes all JavaScript commands in strict mode or default (sloppy) mode.
645645 Acceptable values are:
@@ -656,7 +656,7 @@ changes:
656656 there are no previews and the value of ` preview ` has no effect.
657657* Returns: {repl.REPLServer}
658658
659- The ` repl.start() ` method creates and starts a [ ` repl.REPLServer ` ] [ 11 ] instance.
659+ The ` repl.start() ` method creates and starts a [ ` repl.REPLServer ` ] [ ] instance.
660660
661661If ` options ` is a string, then it specifies the input prompt:
662662
@@ -786,7 +786,7 @@ For an example of running a "full-featured" (`terminal`) REPL over
786786a ` net.Server ` and ` net.Socket ` instance, see:
787787< https://gist.github.com/TooTallNate/2209310 > .
788788
789- For an example of running a REPL instance over [ ` curl(1) ` ] [ 07 ] , see:
789+ For an example of running a REPL instance over [ ` curl(1) ` ] [ ] , see:
790790< https://gist.github.com/TooTallNate/2053342 > .
791791
792792## Experimental REPL
@@ -804,7 +804,7 @@ const experimentalREPL = require('node:repl');
804804### Design and Features
805805
806806When running in experimental mode, the ` node:repl ` module exports the
807- [ ` repl.ExperimentalREPLServer ` ] [ 21 ] class. This class, similar to the
807+ [ ` repl.ExperimentalREPLServer ` ] [ ] class. This class, similar to the
808808stable REPL, accepts individual lines of user input.
809809
810810Most features from the stable REPL are also available in this REPL, including:
@@ -813,8 +813,8 @@ Most features from the stable REPL are also available in this REPL, including:
813813* Completion preview
814814* Simplistic Emacs-style line editing
815815* Multi-line inputs
816- * [ ZSH] [ 02 ] -like [ reverse-i-search] [ 13 ]
817- * [ ZSH] [ 02 ] -like substring-based history search
816+ * [ ZSH] [ ] -like [ ` reverse-i-search ` ] [ ]
817+ * [ ZSH] [ ] -like substring-based history search
818818* ANSI-styled output
819819* Error recovery
820820
@@ -835,7 +835,7 @@ Special commands supported by all ExperimentalREPL instances:
835835* ` .help ` : Shows a list of special commands.
836836* ` .clear ` : Clears the screen.
837837
838- Additional commands may be implemented via the [ ` defineCommand(name, help, fn) ` ] [ 17 ] function.
838+ Additional commands may be implemented via the [ ` defineCommand(name, help, fn) ` ] [ ] function.
839839
840840Special key combinations in the REPL:
841841
@@ -850,8 +850,8 @@ Special key combinations in the REPL:
850850 * Displays global and local (scope) variables on a blank line.
851851 * Displays relevant autocompletion options when pressed while entering other input.
852852
853- For key bindings related to the reverse-i-search, see [ ` reverse-i-search ` ] [ 13 ] .
854- For all other key bindings, see [ TTY keybindings] [ 01 ] .
853+ For key bindings related to the reverse-i-search, see [ ` reverse-i-search ` ] [ ] .
854+ For all other key bindings, see [ TTY keybindings] [ ] .
855855
856856##### Special Variables
857857
@@ -885,9 +885,10 @@ libraries.
885885
886886### Class: ` ExperimentalREPLServer `
887887
888- * Extends: {[ events.EventEmitter] [ 18 ] }
888+ * Extends: {[ events.EventEmitter] [ ] }
889889
890- Instances of the ` repl.ExperimentalREPLServer ` class can be created either via the constructor or the static [ ` repl.start() ` ] [ 19 ] method.
890+ Instances of the ` repl.ExperimentalREPLServer ` class can be created either via the constructor or the static
891+ [ ` repl.start() ` ] [ (Experimental) `repl.start()` ] method.
891892
892893``` cjs
893894(async () => {
@@ -907,7 +908,7 @@ Instances of the `repl.ExperimentalREPLServer` class can be created either via t
907908#### Event: ` 'exit' `
908909
909910The ` 'exit' ` event is emitted when the REPL is exited via the
910- [ ` experimentalReplServer.close() ` ] [ 20 ] method. This event can be useful for
911+ [ ` experimentalReplServer.close() ` ] [ ] method. This event can be useful for
911912cleanup tasks or logging when the REPL session ends.
912913
913914``` js
@@ -983,7 +984,7 @@ experimentalReplServer.preview('os.arch()'); // undefined (as this calls a funct
983984* ` uncaught ` {boolean}: Whether or not an error was incurred.
984985* ` line ` {number}: The line number of the execution.
985986* ` value ` {any}: The output of the line's execution.
986- * Returns: {string}: The [ ` util.inspect() ` ] [ 14 ] ed result of the ` value ` .
987+ * Returns: {string}: The [ ` util.inspect() ` ] [ ] ed result of the ` value ` .
987988
988989The ` experimentalReplServer.updateInspect(uncaught, line, value) ` method
989990updates the underscore variables and returns the inspected result. It's
@@ -1020,8 +1021,8 @@ experimentalReplServer.onLine('.help'); // Prints the help to stdout
10201021#### ` experimentalReplServer.start(options) `
10211022
10221023* ` options ` {Object}: Options for starting the REPL
1023- * ` options.input ` {[ stream] [ 15 ] .Readable}: The input stream for the REPL (_ Default:_ ` process.stdin ` )
1024- * ` options.output ` {[ stream] [ 15 ] .Writable}: The output stream for the REPL (_ Default:_ ` process.stdout ` )
1024+ * ` options.input ` {[ stream] [ ] .Readable}: The input stream for the REPL (_ Default:_ ` process.stdin ` )
1025+ * ` options.output ` {[ stream] [ ] .Writable}: The output stream for the REPL (_ Default:_ ` process.stdout ` )
10251026* Returns: ` Promise<void> `
10261027
10271028The ` experimentalReplServer.start() ` method initializes the REPL session.
@@ -1038,8 +1039,8 @@ The `experimentalReplServer.start()` method initializes the REPL session.
10381039#### ` ExperimentalREPLServer.start(options) `
10391040
10401041* ` options ` {Object}: Options for starting the REPL
1041- * ` options.input ` {[ stream] [ 15 ] .Readable}: The input stream for the REPL (_ Default:_ ` process.stdin ` )
1042- * ` options.output ` {[ stream] [ 15 ] .Writable}: The output stream for the REPL (_ Default:_ ` process.stdout ` )
1042+ * ` options.input ` {[ stream] [ ] .Readable}: The input stream for the REPL (_ Default:_ ` process.stdin ` )
1043+ * ` options.output ` {[ stream] [ ] .Writable}: The output stream for the REPL (_ Default:_ ` process.stdout ` )
10431044* Returns: ` Promise<ExperimentalREPLServer> `
10441045
10451046The ` ExperimentalREPLServer.start(options) ` static method creates and initializes a new REPL.
@@ -1053,26 +1054,24 @@ async () => {
10531054};
10541055```
10551056
1056- <!-- eslint-disable -->
1057-
1058- [ 01 ] : readline.md#tty-keybindings
1059- [ 02 ] : https://en.wikipedia.org/wiki/Z_shell
1060- [ 03 ] : process.md#event-uncaughtexception
1061- [ 04 ] : cli.md#--no-experimental-repl-await
1062- [ 05 ] : errors.md#err_domain_cannot_set_uncaught_exception_capture
1063- [ 06 ] : errors.md#err_invalid_repl_input
1064- [ 07 ] : https://curl.haxx.se/docs/manpage.html
1065- [ 08 ] : domain.md
1066- [ 09 ] : process.md#processsetuncaughtexceptioncapturecallbackfn
1067- [ 10 ] : readline.md#use-of-the-completer-function
1068- [ 11 ] : #class-replserver
1069- [ 12 ] : #replstartoptions
1070- [ 13 ] : #reverse-i-search
1071- [ 14 ] : util.md#utilinspectobject-options
1072- [ 15 ] : stream.md
1073- [ 16 ] : cli.md#--experimental-repl
1074- [ 17 ] : #experimentalreplserverdefinecommandname-help-fn
1075- [ 18 ] : events.md#class-eventemitter
1076- [ 19 ] : #experimentalreplserverstartoptions
1077- [ 20 ] : #experimentalreplserverclose
1078- [ 21 ] : #class-experimentalreplserver
1057+ [ (Experimental) `repl.start()` ] : #experimentalreplserverstartoptions
1058+ [ TTY keybindings ] : readline.md#tty-keybindings
1059+ [ ZSH ] : https://en.wikipedia.org/wiki/Z_shell
1060+ [ `'uncaughtException'` ] : process.md#event-uncaughtexception
1061+ [ `--experimental-repl` ] : cli.md#--experimental-repl
1062+ [ `--no-experimental-repl-await` ] : cli.md#--no-experimental-repl-await
1063+ [ `ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE` ] : errors.md#err_domain_cannot_set_uncaught_exception_capture
1064+ [ `ERR_INVALID_REPL_INPUT` ] : errors.md#err_invalid_repl_input
1065+ [ `curl(1)` ] : https://curl.haxx.se/docs/manpage.html
1066+ [ `defineCommand(name, help, fn)` ] : #experimentalreplserverdefinecommandname-help-fn
1067+ [ `domain` ] : domain.md
1068+ [ `experimentalReplServer.close()` ] : #experimentalreplserverclose
1069+ [ `process.setUncaughtExceptionCaptureCallback()` ] : process.md#processsetuncaughtexceptioncapturecallbackfn
1070+ [ `readline.InterfaceCompleter` ] : readline.md#use-of-the-completer-function
1071+ [ `repl.ExperimentalREPLServer` ] : #class-experimentalreplserver
1072+ [ `repl.REPLServer` ] : #class-replserver
1073+ [ `repl.start()` ] : #replstartoptions
1074+ [ `reverse-i-search` ] : #reverse-i-search
1075+ [ `util.inspect()` ] : util.md#utilinspectobject-options
1076+ [ events.EventEmitter ] : events.md#class-eventemitter
1077+ [ stream ] : stream.md
0 commit comments