Node.js — REPL
What is REPL?
REPL stands for Read-Eval-Print Loop — an interactive JavaScript shell.
node
Basic Usage
> 1 + 1
2
> 'Hello' + ' World'
'Hello World'
> const x = 10
undefined
> x * 2
20
REPL Commands
| Command | Description |
|---|---|
| .help | Show help |
| .exit | Exit REPL |
| .clear | Clear context |
| .save file | Save to file |
| .load file | Load file |
Working with Modules
> const fs = require('fs')
undefined
> fs.readdirSync('.')
['file1.js', 'file2.js']
Multi-line Input
> function add(a, b) {
... return a + b;
... }
undefined
> add(2, 3)
5
Underscore Variable
> 1 + 1
2
> _ + 10
12
REPL Tips
- Use Tab for autocompletion
- Use ↑/↓ for command history
- Use Ctrl+C to cancel
- Use Ctrl+D to exit
Mini Practice
- Start the REPL
- Do some math
- Require a module
- Save REPL session to file
Up Next
Continue with Command Line — Node.js CLI tools.
Related Topics
Frequently Asked Questions about REPL
What is REPL in Node.js?
REPL is a fundamental concept in Node.js. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn REPL?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn REPL.
Why is REPL important in Node.js?
REPL is essential for Node.js development. Understanding this concept will help you write better code and solve real-world problems more effectively.