Node.js
/Beginner
Node REPL
Definition
REPL stands for Read, Eval, Print, Loop. It is the interactive command-line shell that comes with Node.js.
Explain Like I'm New
It's a playground in your terminal. You type `node` and press Enter. Now, you can type JavaScript code directly into your terminal, press Enter, and instantly see the result without having to create or save a `.js` file.
Real World Example
Quickly testing a complex Regex string, or verifying what a specific JavaScript built-in method like `Math.random().toFixed(2)` returns without leaving your terminal.
Common Use Cases
- •Prototyping
- •Debugging JS logic
- •Exploring available modules
Terminal Output
bash / terminal
/*
HOW TO USE THE REPL:
1. Open your terminal.
2. Type: node
3. You will see a `>` prompt.
> const name = "Alice"
undefined
> name.toUpperCase()
'ALICE'
> [1, 2, 3].map(n => n * 2)
[ 2, 4, 6 ]
> const fs = require('fs')
undefined
> .help (Shows available REPL commands)
> .exit (Exits the REPL back to your normal terminal)
*/
console.log("The REPL is an interactive terminal environment. Run 'node' in your terminal to try it!");
Interview Questions
basic
- How do you start the Node REPL?
intermediate
- What does the special `_` (underscore) variable do in the REPL?
advanced
- Can you require custom modules inside the REPL?