Node - Js Console - REPL
Node - Js Console - REPL
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.
You can now test pretty much any Node.js/JavaScript expression in REPL. 10 + 20 will display 30 immediately in new line.
Node.js Examples
You can also define variables and perform some operation on them.
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.
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
To exit from the REPL terminal, press Ctrl + C twice or write .exit and press Enter.
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.
.load filename Load the specified file in the current Node REPL session.
Previous Next
TutorialsTeacher.com Tutorials
TutorialsTeacher.com is optimized for learning web technologies step by step. ASP.NET Core JavaScript
Contact Us C# Angular 2
Object-Oriented C# D3.js
LINQ Sass
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
HOME TERMS OF USE PRIVACY POLICY 2023 TutorialsTeacher.com. All Rights Reserved.
https://www.tutorialsteacher.com/nodejs/nodejs-console-repl 3/3