. Node.js is used for building fast and scalable applications and is an event driven, non-blocking I/O model.
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:
: The result is printed after the evaluation.
: Loops the input command. To come out of NODE REPL, press ctrl+c
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.
Performing Arithmetical operations in REPL
Arithmetical operations in REPL
Performing operations using libraries of NODE. MATH
library is being used in below example.
Math library methods gfg
shows error as the library is referenced as ‘Math’
in NODE and not ‘math’
Using variables in REPL. The keyword var
is used to assign values to variables.
Using Variables in REPL
in REPL. Loops can be used in REPL as in other editors.
Use ctrl – c
to terminate the command and ctrl – c
twice to terminate the NODE REPL.
is used to list out all the commands.
Using .help in REPL
Share your thoughts in the comments
Please Login to comment...