Nodejs REPL

Nodejs comes with a REPL environment. REPL stands for read, eval, print and loop, it’s an interactive environment where users can input the details and the system will print the output in console.

  • Read – reads user input
  • Eval – after reading it will evaluate the date
  • Print – Print the result
  • Loop – continues or repeats the above process until exited

Getting used to REPL, to start the interactive mode type node and enter.

node

Below screenshot shows the output or REPL env.

repl output

Using REPL env with simple maths.

node
2+2
4*4
20+20+18*2

Below Screenshot shows the output of this program.

repl output

Using REPL with variables:

node
var a=10
b =10
a+b

Below screenshot shows the output for this program.

node repl output

Other commands used in REPL:
Ctrl+c – to terminate the current command
Ctrl + c c – to terminate / disconnect from REPL env.
Crtl + d – to exit / disconnect from REPL env.
up/down arrow keys – to check the command history.

Subscribe Now