2 min read
•Question 8 of 62easyWhat is REPL in Node.js?
Understanding the Read-Eval-Print Loop.
What You'll Learn
- What REPL is
- How to use it
- Useful commands
What is REPL?
REPL stands for Read-Eval-Print Loop. It's an interactive shell to execute JavaScript code.
Starting REPL
$ terminalBash
# Start Node REPL
node
# You'll see
>Using REPL
code.jsJavaScript
> 2 + 2
4
> const name = 'Node'
undefined
> console.log(name)
Node
undefined
> [1,2,3].map(x => x * 2)
[ 2, 4, 6 ]REPL Commands
code.jsJavaScript
.help - Show help
.break - Exit multi-line input
.clear - Clear context
.exit - Exit REPL
.save - Save session to file
.load - Load file into session
// Special variable
_ - Last resultExample
code.jsJavaScript
> 5 + 5
10
> _ * 2
20
> .save session.js
Session saved to: session.js