Skip to main content

Command Palette

Search for a command to run...

REPL in Node

Published
1 min read

REPL, which stand for Read Eval Print Loop, is an interactive programming enviroment that allows you to execute Javascript code in the real time time . In Node.js, the REPL functionality provide a Command-Line interface(CLI) where you can type Javascript code and see the result immediately.

Why to use REPL ?

REPL is useful for the Various task , such as

  • Quick Testing

  • Experimentation

  • Debugging

How to Use REPL in Node.js

To start the NodeJs REPL , simply type node in your Terminal and press Enter, You'll enter the REPL mode, where you can type JavaScript code interactively. Here's a basic example:

$ node
> 1 + 1
2
> let greeting = 'Hello, world!'
undefined
> console.log(greeting)
Hello, world!
undefined

Common REPL commands:

  • .help: Shows a list of special REPL commands.

  • .break: Gets you out if you get stuck.

  • .clear: Clears the REPL context.

  • .exit: Exits the REPL.

  • .load: Loads a JavaScript file into the REPL session.

  • .save: Saves all evaluated commands in this REPL session to a file.

  • .editor: Enter editor mode.

Thank You