Node.js can be used in two different ways: in an interactive shell/console
(REPL environment) or by providing it a JavaScript file to execute.
The REPL (Read-Eval-Print-Loop)
module allows users to perform the following tasks:
Read − Reads user’s input, parses it into JavaScript data-structure and stores in memory
Eval − Takes and evaluates the data structure
Print − Prints the result
Loop − Loops the above command until the user presses ctrl-c
twice
When to use of Node.js REPL ?
- REPL terminal is useful to test and debug code.
- The system directly involved with our expressions/commands.
REPL can be started by simply running node on terminal without any arguments.
How to use variables
If var
keyword is not used, then the value is stored in the variable and printed, otherwise the value is stored but not printed. When undefined
is printed means that the above command doesn’t return anything.
Node REPL supports multiline expression similar to JavaScript:
REPL Commands
ctrl + c
− terminate the current command.
ctrl + c twice
− terminate the Node REPL.
ctrl + d
− terminate the Node REPL.
Up/Down Keys
− see command history and modify previous commands.
tab Keys
− list of current commands.
.help
− list of all commands.
.break
− exit from multiline expression.
.clear
− exit from multiline expression.
.save filename
− save the current Node REPL session to a file.
.load filename
− load file content in current Node REPL session.
Opinions