REPL Terminal

REPL (Read Eval Print Loop)

Refers to an environment where the system returns a value when the user enters a command, similar to the Windows command prompt or UNIX/LINUX Shell

Node.js comes with a REPL environment and can perform the following functions

  • Read

    : Reads the user's input, converts it into JavaScript data structures, and stores it in memory

  • Eval

    : Evaluates (processes) the data

  • Print

    : Prints the result

  • Loop

    : Repeats Read, Eval, Print until the user presses ctrl + c twice to exit

Node.js's REPL environment is useful for testing & debugging JavaScript code!

Starting REPL

REPL can be started by running node without any parameters in the Shell / Console

1. Using simple expressions

2. Using variables

  • Like other scripts, you can store values in variables and print them later

  • When using the var keyword

  • The value of the variable is not printed when the command is entered,

  • When the var keyword is not used

    • The value of the variable is printed

  • You can print using console.log()

3. Using Multi-line Expressions

Run a do-while loop in REPL!

Underscore(_) Variable

The underscore variable refers to the most recent result!

REPL Commands

  • ctrl + c

    : terminate the current command

  • ctrl + c twice

    : terminate the Node REPL

  • ctrl + d

    : terminate the Node REPL.

  • Up/Down keys

    : see command history and modify previous commands

  • Tab

    : list of current commands

  • .help

    : list of all commands

  • .break

    : exit from multiline expression

  • .clear

    : exit from multiline expression

  • .save [filename]

    : save the current Node REPL session to a file

  • .load [filename]

    : load file content in current Node REPL session

Stopping REPL

As mentioned above, use ctrl + c twice to come out of Node.js REPL

Last updated