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.
Let’s discuss REPL( Read, Eval, Print and Loop) in details. REPL performs the below given tasks:
|S. No||REPL command||REPL command Description|
|2||Eval||evaluates the java Script data structure|
|3||Prints / Display the response/ output|
|4||Loop||executes the print command till user presses Ctrl+C twice|
Table of Contents
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
|5||tab key||displays list of current commands|
|6||.help||displays list of help commands|
|7||.break||exit from multiple line expression|
|8||.clear||exit from multiple line expression|
|9||.save <filename>||saves the node REPL Session into the file|
|10||.load <filename>||loads the saved file content in the current node REPL Session|