REPL (READ, EVAL, PRINT, LOOP) is a computer environment similar to Shell (Unix/Linux) and command prompt. Node comes with the REPL environment when it is installed. System interacts with the user through outputs of commands/expressions used. It is useful in writing and debugging the codes. The work of REPL can be understood from its full form:
Print : The result is printed after the evaluation.
Loop : Loops the input command. To come out of NODE REPL, press ctrl+c twice
Getting Started with REPL:
To start working with REPL environment of NODE; open up the terminal (in case of UNIX/LINUX) or the Command prompt (in case of Windows) and write node and press ‘enter’ to start the REPL.
The REPL has started and is demarcated by the ‘>’ symbol. Various operations can be performed on the REPL. Below are some of the examples to get familiar with the REPL environment.
Example: Performing Arithmetical operations in REPL
Example: Performing operations using libraries of NODE. MATH library is being used in below example.
Note: using ‘math’ shows error as the library is referenced as ‘Math’ in NODE and not ‘math’.
Example: Using variables in REPL. The keyword var is used to assign values to variables.
Example: Using loops in REPL. Loops can be used in REPL as in other editors.
Note: Use ctrl – c to terminate the command and ctrl – c twice to terminate the NODE REPL.
.help is used to list out all the commands.