The best Node.js REPL (interactive interpreter) Tutorial In 2024, In this tutorial you can learn REPL command,Stop REPL,Gif examples demonstrate,
Node.js REPL (Read Eval Print Loop: interactive interpreter) represents a computer environment, similar to the Window System terminal or Unix / Linux shell, we can enter the command in a terminal, and receives response of the system.
Node comes with an interactive interpreter, you can perform the following tasks:
Reading - to read user input, the Javascript parse the input data structure and stored in memory.
Implementation - Implementation of input data structure
Print - output
Cycle - Cycle the above steps until you press ctrl-ctwice to exit.
Node interactive interpreter can be a good debugging Javascript code.
Start learning REPL
We can enter the following command to start Node terminal:
$ node >
Then we can enter a simple expression> after, and press Enter to calculate the results.
Let's perform simple mathematical operations Node.js REPL command line window:
$ node > 1 +4 5 > 5 / 2 2.5 > 3 * 6 18 > 4 - 1 3 > 1 + ( 2 * 3 ) - 4 3 >
You can be in a variable, and you need to use it to store data.
Variable declarations need to usethe var keyword, if you do not use the var keyword variable will be printed out directly.
A variable using thevar keyword can use console.log () to output variables.
$ node > x = 10 10 > var y = 10 undefined > x + y 20 > console.log("Hello World") Hello World undefined > console.log("www.w3write.com") www.w3write.com undefined
Node REPL support entering multiple lines of expression, which is somewhat similar to JavaScript. Let us perform a do-while loop:
$ node > var x = 0 undefined > do { /en. x++; /en. console.log("x: " + x); /en. } while ( x < 5 ); x: 1 x: 2 x: 3 x: 4 x: 5 undefined >
/en. Symbol of three points is automatically generated, you can line feed after a carriage return.Node will automatically detect whether the expression is continuous.
You can use underscores (_) to obtain an expression of the operation result:
$ node > var x = 10 undefined > var y = 20 undefined > x + y 30 > var sum = _ undefined > console.log(sum) 30 undefined >
ctrl + c - exit the current terminal.
Press ctrl + c twice - Exit Node REPL.
ctrl + d - Exit Node REPL.
Up / Down keys - view the history commands entered.
tab key - list the current command
.help - listed using the command
.break - Exit multi-line expression
.clear - Exit multi-line expression
.save filename - save the current Node REPL session to a specified file
.load filename - the file to load the contents of the current Node REPL session.
We've already mentioned two pressctrl + c construction can exit REPL:
$ node > (^C again to quit) >
Next we show you examples by Gif Pictured actions: