What is REPL in Node.js?
REPL stands for Read-Eval-Print-Loop.
REPL is a Node shell - A virtual environment where a command is entered and the system responds with an output.
Node.js comes bundled with a REPL environment.
- Read − Reads user's input.
- Eval − evaluates the data.
- Print − Prints the result.
- Loop − Loops until the user presses the ctrl-c twice.
> 10 + 1
> 11 + ( 4 / 2 ) - 8
Commands & Keys for REPL :
.break - This command (or pressing the <ctrl>-C key combination) will abort further input or processing of that expression.
.clear - Resets the REPL and clears any multi-line expression.
.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>-D to finish, <ctrl>-C to cancel).
ctrl + c Terminate the current command.
ctrl + c (twice) Terminate the Node REPL.
ctrl + d Exit from the REPL.