Running JavaScript in Node.js REPL
What you'll learn: How to launch Node.js's interactive shell and run JavaScript commands directly without creating files.
What is the REPL?
REPL stands for Read-Eval-Print Loop. It's an interactive programming environment where you type JavaScript code, and Node.js immediately executes it and shows you the result. Think of it like having a conversation with JavaScript—you say something, it responds instantly.
This is similar to the browser console you learned about earlier, but it runs in your terminal using the Node.js runtime instead of a browser.
Launching the REPL
Open your terminal (Command Prompt, PowerShell, or Terminal app) and type:
node
Press Enter. You'll see a prompt that looks like this:
>
This > symbol means Node.js is waiting for your JavaScript commands.
Running JavaScript Commands
Now you can type any JavaScript directly:
> 5 + 3
8
> "Hello" + " World"
'Hello World'
Each time you press Enter, Node.js reads your code, evaluates it, prints the result, and loops back—waiting for your next command.
Exiting the REPL
To leave the REPL and return to your normal terminal, type:
.exit
Or press Ctrl+C twice (or Ctrl+D once on Mac/Linux).
Why Use the REPL?
The REPL is perfect for quick experiments, testing small pieces of code, or learning new JavaScript concepts without creating full files. It's your JavaScript playground.
Key Takeaway: The Node.js REPL lets you execute JavaScript interactively in your terminal—type node to start, enter commands, see instant results, and type .exit to quit.