4/23/23, 1:10 AM Node.
js Console/REPL
Previous Next
Node.js Console/REPL
Node.js comes with virtual environment called REPL (aka Node shell). REPL stands for Read-Eval-Print-Loop. It is a quick and easy way to test simple
Node.js/JavaScript code.
To launch the REPL (Node shell), open command prompt (in Windows) or terminal (in Mac or UNIX/Linux) and type node as shown below. It will change the
prompt to > in Windows and MAC.
Launch Node.js REPL
You can now test pretty much any Node.js/JavaScript expression in REPL. 10 + 20 will display 30 immediately in new line.
The + operator also concatenates strings as in browser's JavaScript.
Node.js Examples
You can also define variables and perform some operation on them.
Define Variables on REPL
If you need to write multi line JavaScript expression or function then just press Enter whenever you want to write something in the next line as a
continuation of your code. The REPL terminal will display three dots (...), it means you can continue on next line. Write .break to get out of continuity mode.
For example, you can define a function and execute it as shown below.
Node.js Example in REPL
You can execute an external JavaScript file by executing the node fileName command. For example, the following runs mynodejs-app.js on the command
prompt/terminal and displays the result.
mynodejs-app.js Copy
console.log("Hello World");
Now, you can execute mynodejs-app from command prompt as shown below.
https://www.tutorialsteacher.com/nodejs/nodejs-console-repl 1/3
4/23/23, 1:10 AM Node.js Console/REPL
Run External JavaScript file
To exit from the REPL terminal, press Ctrl + C twice or write .exit and press Enter.
Quit from REPL
Thus, you can execute any Node.js/JavaScript code in the node shell (REPL). This will give you a result which is similar to the one you will get in the console
of Google Chrome browser.
The following table lists important REPL commands.
REPL Command Description
.help Display help on all the commands
tab Keys Display the list of all commands.
Up/Down Keys See previous commands applied in REPL.
.save filename Save current Node REPL session to a file.
.load filename Load the specified file in the current Node REPL session.
ctrl + c Terminate the current command.
ctrl + c (twice) Exit from the REPL.
ctrl + d Exit from the REPL.
.break Exit from multiline expression.
.clear Exit from multiline expression.
Want to check how much you know Node.js?
Start Node.js Test
Previous Next
Share Tweet Share Whatsapp
TutorialsTeacher.com Tutorials
TutorialsTeacher.com is optimized for learning web technologies step by step. ASP.NET Core JavaScript
Examples might be simplified to improve reading and basic understanding.
ASP.NET MVC jQuery
While using this site, you agree to have read and accepted our terms of use
and privacy policy. IoC Typescript
Web API Node.js
Contact Us C# Angular 2
Object-Oriented C# D3.js
LINQ Sass
Python Https (SSL)
Go Lang AngularJS 1
SQL
SQL Server
MongoDB
PostgreSQL
Entity Framework
E-mail list
Subscribe to TutorialsTeacher email list and get latest updates, tips & tricks on C#, .Net, JavaScript, jQuery, AngularJS, Node.js to your inbox.
https://www.tutorialsteacher.com/nodejs/nodejs-console-repl 2/3
4/23/23, 1:10 AM Node.js Console/REPL
Email address GO
We respect your privacy.
HOME TERMS OF USE PRIVACY POLICY 2023 TutorialsTeacher.com. All Rights Reserved.
https://www.tutorialsteacher.com/nodejs/nodejs-console-repl 3/3