Blog Post

No logo
REPL Terminal - Node.js

REPL Terminal - Node.js

REPL stands for Read Eval Print Loop and it represents a computer environment like a Windows console or Unix/Linux shell where a command is entered and the system responds with an output in an interactive mode. Node.js or Node comes bundled with a REPL environment. It performs the following tasks −

  • Read − Reads user's input, parses the input into JavaScript data-structure, and stores in memory.
  • Eval − Takes and evaluates the data structure.
  • Print − Prints the result.
  • Loop − Loops the above command until the user presses ctrl-c twice.

The REPL feature of Node is very useful in experimenting with Node.js codes and to debug JavaScript codes.

Starting REPL

REPL can be started by simply running node on shell/console without any arguments as follows.

$ node

Stopping REPL

As mentioned above, you will need to use ctrl-c twice to come out of Node.js REPL

$ node

>

(^C again to quit)

>

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 Keys − 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