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.
open node 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
Arithmetical operations in REPL
Example: Performing operations using libraries of NODE. MATH library is being used in below example.
Math library methods gfg
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.
Using Variables in REPL
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.
Using .help in REPL
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!