REPL (Node.js)

The Node.js REPL (Read-Eval-Print Loop) is the interactive shell you get by running node with no file. You type JavaScript, it evaluates each line immediately and prints the result, making it ideal for quick experiments.

Node.js

Run node alone and you enter the REPL, an interactive prompt where each expression you type is executed and its result shown at once. It is perfect for trying out an API, testing a snippet, or doing quick calculations without creating a file.

The REPL reads your input, evaluates it, prints the result, and loops — hence Read-Eval-Print Loop. It keeps state between lines, so variables you define persist for the session, and the special _ variable holds the last result. Multi-line input (like a function) is supported automatically.

Handy REPL commands start with a dot: .help lists them, .load runs a file, .save writes your session to a file, .clear resets context, and .exit (or Ctrl+D) quits. Core modules like fs are available without require in the REPL for convenience.

Syntax

$ node   // then type JavaScript at the > prompt

Examples

JavaScript

// $ node
> 2 + 3
5
> const name = "Node"
undefined
> `Hello ${name}`
'Hello Node'
> .exit

Learn it in a lesson

See also

Back to the Dictionary