The REPL

An Interactive JS Shell — Right in Your Terminal

The REPL

Type `node` to drop into an interactive JS shell. Great for trying one-liners and exploring APIs.

2 min read Level 1/5 #nodejs#repl#basics
What you'll learn
  • Start and exit the REPL
  • Run multi-line statements
  • Use `_` for the last result

The REPL (Read, Eval, Print, Loop) is an interactive Node shell. Type node with no arguments — you get a > prompt.

Basic Use

$ node
Welcome to Node.js v22.x.
Type ".help" for more information.
> 2 + 2
4
> const name = "world"
undefined
> `hello, ${name}`
'hello, world'
> _
'hello, world'
  • _ always refers to the result of the last expression
  • Press Tab for autocomplete (object properties, built-ins)
  • Press Ctrl+D (or type .exit) to quit

Multi-line

The REPL auto-detects unclosed brackets and continues on the next line:

> function greet(name) {
...   return `hi, ${name}`;
... }
undefined
> greet("ada")
'hi, ada'

Dot Commands

> .help        # list commands
> .editor      # paste/edit a block; Ctrl+D to evaluate
> .load file.js   # load a file into the REPL
> .save out.js    # save the session
> .clear       # reset context

When to Use It

  • Quickly test an API: > require("crypto").randomUUID()
  • Sanity-check a regex
  • Explore the shape of a returned value

For real work, write .mjs files and run them — covered next.

Running Scripts →