The Wayback Machine - https://web.archive.org/web/20240731120324/https://www.geeksforgeeks.org/node-js-repl-read-eval-print-loop/
Open In App

Node.js REPL (READ, EVAL, PRINT, LOOP)

Last Updated : 29 Apr, 2018
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

Node.js is an open source server-side JavaScript run-time environment built on Chrome’s JavaScript Engine(V8). 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:

Read : It reads the inputs from users and parses it into JavaScript data structure. It is then stored to memory.
Eval : The parsed JavaScript data structure is evaluated for the results.
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 gfg

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

simple math arithmetic gfg

Arithmetical operations in REPL

Example: Performing operations using libraries of NODE. MATH library is being used in below example.

Math library methods gfg

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.

variable assignment gfg

Using Variables in REPL

Example: Using loops in REPL. Loops can be used in REPL as in other editors.
multiline expression gfg

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.

repl help gfg

Using .help in REPL


Previous Article
Next Article

Similar Reads

How to use Node.js REPL ?
Node.Js REPL or Read-Evaluate-Print Loop is an interactive shell for the Node.js environment which means we can write any valid Javascript code in it. This is used to test, evaluate, experiment, or debug code much easier and accessible way. It basically acts as the Browser's Web dev tools' Console for Javascript. To use the REPL, you must have Node
6 min read
What is the use of underscore variable in REPL ?
In the previous Node.js REPL post, we've discussed what is Node.js REPL and how to use it on your command prompt. We've also discussed how to perform arithmetical operations, how to use node library functions, and how to use loops in REPL. In this article, we're going to discuss what is the use of the underscore (_) variable in Node.JS REPL. Unders
2 min read
What is REPL in NodeJS?
REPL, which stands for Read Eval Print Loop, is an interactive programming environment that allows you to execute JavaScript code in real-time. In NodeJS, the REPL functionality provides a command-line interface where you can type JavaScript code and see the results immediately. What is REPL?REPL, short for Read Eval Print Loop, is a programming en
2 min read
PHP eval() Function
PHP eval() function in PHP is an inbuilt function that evaluates a string as PHP code. Syntax: eval( $string ) Parameters: This function accepts a single parameter as shown in the above syntax and described below. $string: It must consist of a valid PHP code to be evaluated but should not contain opening and closing PHP tags. Note: All statements m
2 min read
Is JavaScript's eval() evil?
The eval() is an in-built JS function that evaluates arguments that are expressions and executes one or more statements given to it as arguments. Reason eval() is considered evil: There are several problems possessed by the use of eval() and out of all performance and code injection are considered the most problematic. Performance- since the script
2 min read
Why should you avoid the JavaScript eval() function?
What is the eval() function? The eval() function is used to evaluate the expression. If the argument represents one or more JavaScript statements, eval() evaluates the statements. We do not call eval() to evaluate an arithmetic expression. JavaScript evaluates arithmetic expressions automatically. Syntax: eval(string) Example: C/C++ Code // JavaScr
2 min read
JavaScript eval() Function
The eval() method in JavaScript evaluates or executes its argument. If the argument is an expression, it evaluates the expression. If it's one or more JavaScript statements, eval() executes the statements. Note: eval(): This function was used to evaluate a string as JavaScript code, but it is now considered deprecated because it can introduce secur
4 min read
eval() vs. Function() in JavaScript
We will learn about JavaScript functions eval() and Function(). The eval() and Function() are used to evaluate any JavaScript expression passed to either of them as a string but the difference between them is how how they handle the expression. eval() The eval() method in JavaScript evaluates or executes its argument. If the argument is an expressi
2 min read
Create a Read More Read Less Button using HTML CSS and JavaScript
The "read more - read less" button is a commonly used feature that enhances user experience by providing a convenient way to reveal or hide content. The article covers two distinct approaches, including Display Inline and Display Block. Table of Content Using Display InlineUsing Display BlockUsing Display InlineCreate a separate HTML, CSS, and Java
4 min read
How to Loop Through an Array using a foreach Loop in PHP?
Given an array (indexed or associative), the task is to loop through the array using foreach loop. The foreach loop iterates through each array element and performs the operations. PHP foreach LoopThe foreach loop iterates over each key/value pair in an array. This loop is mainly useful for iterating through associative arrays where you need both t
2 min read
three90RightbarBannerImg