Options
All
  • Public
  • Public/Protected
  • All
Menu

Provides a customizable Read-Eval-Print-Loop (REPL).

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.

Instances of repl.REPLServer are created using the repl.start() method and should not be created directly using the JavaScript new keyword.

see

https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_repl

Hierarchy

Index

Constructors

Private constructor

Properties

commands

commands: object

The commands registered via replServer.defineCommand().

Type declaration

completer

Specified in the REPL options, this is the function to use for custom Tab auto-completion.

context

context: Context

The vm.Context provided to the eval function to be used for JavaScript evaluation.

editorMode

editorMode: boolean

A value indicating whether the REPL is currently in "editor mode".

see

https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_commands_and_special_keys

eval

eval: REPLEval

Specified 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.

ignoreUndefined

ignoreUndefined: boolean

Specified 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.

inputStream

inputStream: ReadableStream

The Readable stream from which REPL input will be read.

last

last: any

The last evaluation result from the REPL (assigned to the _ variable inside of the REPL).

see

https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable

lastError

lastError: any

The last error raised inside the REPL (assigned to the _error variable inside of the REPL).

since

v9.8.0

see

https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable

outputStream

outputStream: WritableStream

The Writable stream to which REPL output will be written.

replMode

replMode: symbol | symbol

Specified 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'.

terminal

terminal: boolean

underscoreAssigned

underscoreAssigned: boolean

A value indicating whether the _ variable has been assigned.

see

https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable

underscoreErrAssigned

underscoreErrAssigned: boolean

A value indicating whether the _error variable has been assigned.

since

v9.8.0

see

https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable

useColors

useColors: boolean

Specified in the REPL options, this is a value indicating whether the default writer function should include ANSI color styling to REPL output.

useGlobal

useGlobal: boolean

Specified 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.

writer

writer: REPLWriter

Specified 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.

Static defaultMaxListeners

defaultMaxListeners: number

Methods

__@asyncIterator

addListener

  • addListener(event: string, listener: function): this
  • addListener(event: "close", listener: function): this
  • addListener(event: "line", listener: function): this
  • addListener(event: "pause", listener: function): this
  • addListener(event: "resume", listener: function): this
  • addListener(event: "SIGCONT", listener: function): this
  • addListener(event: "SIGINT", listener: function): this
  • addListener(event: "SIGTSTP", listener: function): this
  • addListener(event: "exit", listener: function): this
  • addListener(event: "reset", listener: function): this
  • events.EventEmitter

    1. close - inherited from readline.Interface
    2. line - inherited from readline.Interface
    3. pause - inherited from readline.Interface
    4. resume - inherited from readline.Interface
    5. SIGCONT - inherited from readline.Interface
    6. SIGINT - inherited from readline.Interface
    7. SIGTSTP - inherited from readline.Interface
    8. exit
    9. reset

    Parameters

    • event: string
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

  • Parameters

    • event: "close"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "line"
    • listener: function
        • (input: string): void
        • Parameters

          • input: string

          Returns void

    Returns this

  • Parameters

    • event: "pause"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "resume"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "SIGCONT"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "SIGINT"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "SIGTSTP"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "exit"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "reset"
    • listener: function

    Returns this

clearBufferedCommand

  • clearBufferedCommand(): void
  • 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.

    since

    v9.0.0

    Returns void

close

  • close(): void
  • Returns void

defineCommand

displayPrompt

  • displayPrompt(preserveCursor?: undefined | false | true): void
  • 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'.

    This method is primarily intended to be called from within the action function for commands registered using the replServer.defineCommand() method.

    Parameters

    • Optional preserveCursor: undefined | false | true

      When true, the cursor placement will not be reset to 0.

    Returns void

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • emit(event: "close"): boolean
  • emit(event: "line", input: string): boolean
  • emit(event: "pause"): boolean
  • emit(event: "resume"): boolean
  • emit(event: "SIGCONT"): boolean
  • emit(event: "SIGINT"): boolean
  • emit(event: "SIGTSTP"): boolean
  • emit(event: "exit"): boolean
  • emit(event: "reset", context: Context): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

  • Parameters

    • event: "close"

    Returns boolean

  • Parameters

    • event: "line"
    • input: string

    Returns boolean

  • Parameters

    • event: "pause"

    Returns boolean

  • Parameters

    • event: "resume"

    Returns boolean

  • Parameters

    • event: "SIGCONT"

    Returns boolean

  • Parameters

    • event: "SIGINT"

    Returns boolean

  • Parameters

    • event: "SIGTSTP"

    Returns boolean

  • Parameters

    • event: "exit"

    Returns boolean

  • Parameters

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>

getMaxListeners

  • getMaxListeners(): number

listenerCount

  • listenerCount(type: string | symbol): number

listeners

  • listeners(event: string | symbol): Function[]

off

  • off(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string, listener: function): this
  • on(event: "close", listener: function): this
  • on(event: "line", listener: function): this
  • on(event: "pause", listener: function): this
  • on(event: "resume", listener: function): this
  • on(event: "SIGCONT", listener: function): this
  • on(event: "SIGINT", listener: function): this
  • on(event: "SIGTSTP", listener: function): this
  • on(event: "exit", listener: function): this
  • on(event: "reset", listener: function): this
  • Parameters

    • event: string
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

  • Parameters

    • event: "close"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "line"
    • listener: function
        • (input: string): void
        • Parameters

          • input: string

          Returns void

    Returns this

  • Parameters

    • event: "pause"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "resume"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "SIGCONT"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "SIGINT"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "SIGTSTP"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "exit"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "reset"
    • listener: function

    Returns this

once

  • once(event: string, listener: function): this
  • once(event: "close", listener: function): this
  • once(event: "line", listener: function): this
  • once(event: "pause", listener: function): this
  • once(event: "resume", listener: function): this
  • once(event: "SIGCONT", listener: function): this
  • once(event: "SIGINT", listener: function): this
  • once(event: "SIGTSTP", listener: function): this
  • once(event: "exit", listener: function): this
  • once(event: "reset", listener: function): this
  • Parameters

    • event: string
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

  • Parameters

    • event: "close"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "line"
    • listener: function
        • (input: string): void
        • Parameters

          • input: string

          Returns void

    Returns this

  • Parameters

    • event: "pause"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "resume"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "SIGCONT"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "SIGINT"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "SIGTSTP"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "exit"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "reset"
    • listener: function

    Returns this

pause

  • pause(): this
  • Returns this

prependListener

  • prependListener(event: string, listener: function): this
  • prependListener(event: "close", listener: function): this
  • prependListener(event: "line", listener: function): this
  • prependListener(event: "pause", listener: function): this
  • prependListener(event: "resume", listener: function): this
  • prependListener(event: "SIGCONT", listener: function): this
  • prependListener(event: "SIGINT", listener: function): this
  • prependListener(event: "SIGTSTP", listener: function): this
  • prependListener(event: "exit", listener: function): this
  • prependListener(event: "reset", listener: function): this
  • Parameters

    • event: string
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

  • Parameters

    • event: "close"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "line"
    • listener: function
        • (input: string): void
        • Parameters

          • input: string

          Returns void

    Returns this

  • Parameters

    • event: "pause"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "resume"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "SIGCONT"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "SIGINT"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "SIGTSTP"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "exit"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "reset"
    • listener: function

    Returns this

prependOnceListener

  • prependOnceListener(event: string, listener: function): this
  • prependOnceListener(event: "close", listener: function): this
  • prependOnceListener(event: "line", listener: function): this
  • prependOnceListener(event: "pause", listener: function): this
  • prependOnceListener(event: "resume", listener: function): this
  • prependOnceListener(event: "SIGCONT", listener: function): this
  • prependOnceListener(event: "SIGINT", listener: function): this
  • prependOnceListener(event: "SIGTSTP", listener: function): this
  • prependOnceListener(event: "exit", listener: function): this
  • prependOnceListener(event: "reset", listener: function): this
  • Parameters

    • event: string
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

  • Parameters

    • event: "close"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "line"
    • listener: function
        • (input: string): void
        • Parameters

          • input: string

          Returns void

    Returns this

  • Parameters

    • event: "pause"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "resume"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "SIGCONT"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "SIGINT"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "SIGTSTP"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "exit"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "reset"
    • listener: function

    Returns this

prompt

  • prompt(preserveCursor?: undefined | false | true): void
  • Parameters

    • Optional preserveCursor: undefined | false | true

    Returns void

question

  • question(query: string, callback: function): void
  • Parameters

    • query: string
    • callback: function
        • (answer: string): void
        • Parameters

          • answer: string

          Returns void

    Returns void

rawListeners

  • rawListeners(event: string | symbol): Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): this

removeListener

  • removeListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

resume

  • resume(): this
  • Returns this

setMaxListeners

  • setMaxListeners(n: number): this

setPrompt

  • setPrompt(prompt: string): void
  • Parameters

    • prompt: string

    Returns void

setupHistory

  • setupHistory(path: string, cb: function): void
  • 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.

    Parameters

    • path: string

      The path to the history file

    • cb: function
        • (err: Error | null, repl: this): void
        • Parameters

          • err: Error | null
          • repl: this

          Returns void

    Returns void

write

  • write(data: string | Buffer, key?: Key): void
  • Parameters

    • data: string | Buffer
    • Optional key: Key

    Returns void

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    Returns number

Generated using TypeDoc