REPL in Node

Sonu KumarSonu Kumar
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

10
Subscribe to my newsletter

Read articles from Sonu Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sonu Kumar
Sonu Kumar