Node.js REPL Tutorial

The tutorial provides insight on the node.js REPL( Read Eval Print Loop) Tutorial. The node.js REPL provides the console to execute the commands similar to Windows Console or Linux Console where executed commands receives the response / output in an interactive mode.

How to start REPL

To start the REPL, you need to enter the “node” command in the node.js command prompt

Node.js – create expressions using REPL

Node.js command prompt is to be used for entering the expressions by executing the below given example

Node.js – variable assigment using REPL

The Node.js allows to create variables to store the value like other scripting languages. The var command is used to create variable but values store using var cannot be printed directly and we need to use the console.log() for printing variable values.

The variable beta value is printed but using the console.log function.

If var keyword is not used , then the value is stored in the variable and printed. The variable aplha is only printed with the value.

Nodejs – REPL underscore variable

The underscore (_) variable is used in node.js to get the last result

The variable sum uses (_) which captures the sum value of alpha and beta

Node.js multiple line expressions ( Loop in REPL)

Node.js provides the multiple line expression just like other scripting language . The common example could be a do..while loop where the value of alpha is incremented .

Node.js REPL commands

The below given are the avaialbel node.js REPL commands

S. No

REPL commands

REPL command Description

1

ctrl +c

terminates the current command

2

ctrl+ c ( 2 times)

terminates the node REPL

3

ctrl +d

terminates the node REPL

4

up /down keys

up key -> displays command history down key -> modify the previous command