How to Open Node.js Command Prompt ?
Node.js enables the execution of JavaScript code outside a web browser. It is not a framework or a programming language, but rather a backend JavaScript runtime environment that allows scripts to be executed outside the browser. You can download Node.js from the web by visiting the link “Download Node” and downloading the latest version onto your machine. In this article, we will discuss how to open Node.js using a command prompt.
Table of Content
- Installing Node.js on the machine
- Opening Node Command Prompt
- Performing some operations on REPL
- REPL commands
Installing Node.js on the machine
First of all, we have to check whether the node.js is installed on our machine or not. To check type “node –version” on the command prompt. If the installed version appears on the machine .Node.js is already installed on your machine otherwise we have to install the latest version of the node.js. Refer to this article to learn the process of installing Node.js on your machine.
Opening Node Command Prompt
Node js comes with a virtual environment called REPL (READ, EVAL, PRINT, LOOP). It is a computer environment the same as command prompt and an easy way to test simple Node.js/JavaScript code and allows to execute multiple javascript codes. we can simply run REPL on the command prompt using node command on the command prompt.
Use the below command in the terminal to open the Node Command Prompt
node
Performing some operations on REPL
These are the examples of performing basic operations on REPL
- Addition of the two numbers: We can add two numbers using “+” Operator.
- Defining variables and assigning values to the variables: When you print the value or write some valid statements like defining variables etc it also returns undefined. JavaScript functions always return something therefore by default undefined is returned.
- Execution for loop on REPL: We can execute for loop on the Node.js REPL in multiline same as in the javascript. This is called multiline expression.
REPL commands
These commands help to manipulate or communicate with the node.js commands on the REPL
Commands | Description |
.help | List out all the commands |
Ctrl + C | To terminate the command |
Ctrl + C {twice} / Ctrl + D | To exit the command prompt |
Tab | Displays all functions and objects. |
.clear | To clear multi-lines expression |
Executing REPL Commands
Reference: https://nodejs.dev/learn/how-to-use-the-nodejs-repl