Node.js REPL (Read-Eval-Print Loop)

📘 Node.js 👁 50 views 📅 Nov 05, 2025
⏱ Estimated reading time: 1 min

The Node.js REPL is an interactive environment that allows you to execute JavaScript code line by line and immediately see the output.


1. REPL Cycle

  1. Read – Reads the user input

  2. Eval – Evaluates the JavaScript code

  3. Print – Displays the result

  4. Loop – Waits for the next command


2. Starting the REPL

Open a terminal and type:

node

You will see:

>

3. Basic Usage

> 2 + 3 5 > let x = 10; undefined > x * 2 20

4. Special REPL Commands

CommandDescription
.helpList all REPL commands
.exitExit the REPL
.clearClear the context
.save file.jsSave session to a file
.load file.jsLoad a file into REPL

5. Multiline Code

> function add(a, b) { ... return a + b; ... }

6. Global Objects Access

You can directly access:

  • console

  • process

  • global

  • __dirname

  • __filename


7. Advantages

  • Fast testing and debugging

  • No file creation required

  • Ideal for learning and experimentation


8. Limitations

  • Not suitable for large applications

  • Session data is lost on exit


9. Use Cases

  • Testing small code snippets

  • Debugging logic

  • Exploring Node.js APIs


🔒 Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes