Uses of REPL:
REPL can start by simply running node on the console without any arguments. In the console, you can carry out different operations using variables and different type of expressions.
- Simple expressions:A simple addition, multiplication, division or subtraction can be carried out in the console. For example, enter ‘ 1+2’, it will display the output of 3. Basically, all the simple operations can be carried out in REPL.
- Multiline expressions:You can define conditions and statements inside the console and carry out different operations because Node REPL also supports different types of loops and multiline expressions
- Use of Variable:Variable helps us to store the value, in the same way, REPLY console allows use to declare a variable and stores the value in it. To print the value of the variable, console.log() keyword needs to get declare before declaring the variable otherwise it will just store the value and will not print. For example ‘ console.log(“HELLO WORLD“)’, it will display HELLO WORLD.
There are different commands used in REPL to control the environment of the console.1) .save filename – It saves the current Node session to a file.2) .load filename – It loads the content of node in the current REPL session.3) .break/.clear – It helps to exit from multiline expression.4) .help – It gives you all the list of all commands.5) ctrl + c – It helps you to terminate the current command.6) ctrl + c twice – It will help you to terminate the node REPL.
Conclusion:Basically, Node REPL in node.js helps to 1) Read – read’s user input and helps to store it in the memory.2) Eval – evaluates the structure.3)Print – prints the result.4) Loop – Supports loop to carry out functions in recursive mode. Press Ctrl + C twice to exit the session and the loop effects.
[vc_row][vc_column][td_block_21 separator=”” tag_slug=”node-js” limit=”40″ tdc_css=””][/vc_column][/vc_row]