Node.js Console - REPL
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 also define variables and perform some operation on them.> var x = 10, y = 20;
> x + y
For example, you can define a function and execute it as shown below.
node fileName command. For example, assume that node-example.js is on C drive of your PC with following code.
Now, you can execute node-exampel.js from command prompt as shown below.
To exit from the REPL terminal, press Ctrl + C twice or write .exit and press Enter.
The following table lists important REPL commands.
|.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.|