A Quick Guide to Node.js REPL Commands

You can run instructions one at a time in the interactive shell that comes with the Node.js runtime. The REPL principle—an acronym for READ, EVALUATE, PRINT, and LOOP—is the foundation of the Node.js interactive shell.

The interactive REPL terminal for Node.js is comparable to a Linux bash terminal, Powershell, or Command Prompt terminal. It carries out the following duties:

Read − Reads user’s input, parses the input into JavaScript data-structure, and stores in memory.

Eval − Takes and evaluates the data structure.

Print − Prints the result.

Loop − The terminal is ready to receive next input from the user.

We have created a user-friendly online Node.js REPL environment so you may practice Node.js syntax and make learning easier. Go to Node.js Terminal to start the Node.js REPL Terminal.

Enter node in the command terminal (without the javascript file name as done previously) to launch the Node.js REPL on your PC. You’ll see the Node.js prompt >.

D:\nodejs>node
Welcome to Node.js v20.9.0.
Type ".help"for more information.>

The REPL feature of Node is very useful in experimenting with Node.js codes and to debug JavaScript codes.

You can test any Node.js/JavaScript expression by entering in front of the > prompt. For example −

> 10+20
30
> "Hello"+"World"
'HelloWorld'
> a=10
10
> b=20
20
> a+b
30
> Math.random()
0.5423940959293392
>

You can see that the instruction is read, evaluated, its result displayed and the terminal is ready to receive next instruction. To start the REPL, press ctrl+c twice, or ctrl+D, or enter .exit in front of > symbol.

Multiline Expression

Node REPL supports multiline expression similar to JavaScript. Let’s check the following do-while loop in action −

> x=00>do{... x++;... console.log("x: "+x);...}...while(x<5);x:1x:2x:3x:4x:5undefined>

The three dots … comes automatically when you press Enter after the opening bracket. Node automatically checks the continuity of expressions.

Underscore Variable

You can use underscore (_) to get the last result −

>var x=10undefined>var y=20undefined> x+y
30>var z= _
undefined> z
30>

Dot commands

The REPL has some special commands, all starting with a dot .. They are

Here’s a well-structured table for better readability:

Sr. NoDot CommandDescription
1.helpShows the dot commands help.
2.editorEnables editor mode to write multiline JavaScript code. Press Ctrl+D to execute.
3.breakAborts further input when entering a multi-line expression (same as pressing Ctrl+C).
4.clearResets the REPL context to an empty object and clears any ongoing multi-line expression.
5.loadLoads a JavaScript file relative to the current working directory.
6.saveSaves all entered commands in the REPL session to a specified file.
7.exitExits the REPL session (same as pressing Ctrl+C twice).
8Up/Down KeysNavigates through command history to modify previous commands.
9Tab KeyLists available commands and autocompletes inputs.

This format enhances readability and clarity. Let me know if you need any further refinements! 🚀

It might be helpful:

What’s New in Node.js 21/22? 

Best Practices for API Design in Full-Stack Development

What is REST API with an example?

Error: Contact form not found.

₹25,000.00

SAP SD S4 HANA

SAP SD (Sales and Distribution) is a module in the SAP ERP (Enterprise Resource Planning) system that handles all aspects of sales and distribution processes. S4 HANA is the latest version of SAP’s ERP suite, built on the SAP HANA in-memory database platform. It provides real-time data processing capabilities, improved…
₹25,000.00

SAP HR HCM

SAP Human Capital Management (SAP HCM)  is an important module in SAP. It is also known as SAP Human Resource Management System (SAP HRMS) or SAP Human Resource (HR). SAP HR software allows you to automate record-keeping processes. It is an ideal framework for the HR department to take advantage…
₹25,000.00

Salesforce Administrator Training

I am text block. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.
₹25,000.00

Salesforce Developer Training

Salesforce Developer Training Overview Salesforce Developer training advances your skills and knowledge in building custom applications on the Salesforce platform using the programming capabilities of Apex code and the Visualforce UI framework. It covers all the fundamentals of application development through real-time projects and utilizes cases to help you clear…
₹25,000.00

SAP EWM

SAP EWM stands for Extended Warehouse Management. It is a best-of-breed WMS Warehouse Management System product offered by SAP. It was first released in 2007 as a part of SAP SCM meaning Supply Chain Management suite, but in subsequent releases, it was offered as a stand-alone product. The latest version…
₹25,000.00

Oracle PL-SQL Training Program

Oracle PL-SQL is actually the number one database. The demand in market is growing equally with the value of the database. It has become necessary for the Oracle PL-SQL certification to get the right job. eLearning Solutions is one of the renowned institutes for Oracle PL-SQL in Pune. We believe…
₹25,000.00

Pega Training Courses in Pune- Get Certified Now

Course details for Pega Training in Pune Elearning solution is the best PEGA training institute in Pune. PEGA is one of the Business Process Management tool (BPM), its development is based on Java and OOP concepts. The PAGA technology is mainly used to improve business purposes and cost reduction. PEGA…
₹27,000.00

SAP PP (Production Planning) Training Institute

SAP PP Training Institute in Pune SAP PP training (Production Planning) is one of the largest functional modules in SAP. This module mainly deals with the production process like capacity planning, Master production scheduling, Material requirement planning shop floor, etc. The PP module of SAP takes care of the Master…
WhatsApp WhatsApp us
Call Now Button