REPL stands for Read, Eval, Print, and Loop. Node.js also provides a REPL environment for quicky testing and debugging Node.js code.
You can also store all the commands executed on Node REPL by setting the NODE_REPL_HISTORY environment variable. Node.js REPL will store all commands to the file set with this variable
export NODE_REPL_HISTORY=/var/log/node-repl.log
Use
Start REPL Console
Run command
node
Working with Node.js REPL
Let’s work with the Node.js REPL interface. Start the Node.js REPL interface and run the below examples. You can also try your own example commands.
Simple Arithmetic Operations
Perform some basic arithmetic operatins on Node.js terminal. The result will be shown on the screen.
5+10 1510+(5*3) 25
Using Variables
Now try with some variables. For example store values in two variable and try a simple calculation, You will see the result on screen. You can simply assign a value to the variable like below example.
a=10 10b=15 20(a + b)/2 15
You can also use the var keyword to define the variable value.
var a=10 undefined var b=15 undefined (a + b)/2 15
Let’s try to store a string value to the variable. After that try to print value stored in the variable using the console.log() function.
name="TecAdmin.net" 'TecAdmin.net'console.log(name) TecAdmin.netundefined