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.
For example, you can define a function and execute it as shown below.
node fileName command.
For example, the following runs
mynodejs-app.js on the command prompt/terminal and displays the result.
Now, you can execute
mynodejs-app 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.|