0
0
Node.jsframework~5 mins

REPL for interactive exploration in Node.js

Choose your learning style9 modes available
Introduction

A REPL lets you try out Node.js code quickly and see results right away. It helps you learn and test ideas without writing full programs.

You want to test a small piece of JavaScript code quickly.
You are learning Node.js and want to explore how commands work.
You want to debug or check values step-by-step interactively.
You want to experiment with new Node.js features without creating files.
Syntax
Node.js
node

Just type node in your terminal to start the REPL.

Type JavaScript commands and press Enter to see results immediately.

Examples
Simple math expression typed in REPL returns the result immediately.
Node.js
> 2 + 3
5
Declare a variable and then use it. The REPL shows undefined after declaration because const statements do not return a value.
Node.js
> const name = 'Alice';
undefined
> name
'Alice'
Using console.log prints output, then REPL shows undefined because console.log returns nothing.
Node.js
> console.log('Hello REPL!');
Hello REPL!
undefined
Sample Program

This example shows how you can declare a variable, update it, and print its value interactively in the Node.js REPL.

Node.js
/* Start Node.js REPL by typing 'node' in your terminal */

// Then type these commands interactively:

> let count = 0;
undefined
> count += 1;
1
> count
1
> console.log(`Count is now ${count}`);
Count is now 1
undefined
OutputSuccess
Important Notes

Press Ctrl+C twice or type .exit to leave the REPL.

You can use multi-line input by pressing Enter after incomplete code.

REPL supports history: use up/down arrows to recall previous commands.

Summary

REPL lets you run JavaScript code interactively in Node.js.

It is great for quick testing, learning, and debugging.

Start it by typing node in your terminal and enter commands.