Node.js - REPL Terminal
January 24th 2021 71
The node command is the one we use to run our Node.js scripts:
If we omit the filename, we use it in REPL mode:
Note: REPL also known as Read Evaluate Print Loop is a programming language environment(Basically a console window) that takes single expression as user input and returns the result back to the console after execution.
If you try it now in your
terminal, this is what happens:
❯ node >
the command stays in idle mode and waits for us to enter something.
Tip: if you are unsure how to open your terminal, google "How to open terminal on <your-operating-system>".
Start simple and enter
> console.log('test') test undefined >
The first value, test, is the output we told the console to print, then we get undefined which is the return value of running
- ctrl + c − terminate the current command.
- ctrl + c twice − terminate the Node REPL.
- ctrl + d − terminate the Node REPL.
- Up/Down Keys − see command history and modify previous commands.
- tab Keys − list of current commands.
- .help − list of all commands.
- .break − exit from multiline expression.
- .clear − exit from multiline expression.
- .save filename − save the current Node REPL session to a file.
- .load filename − load file content in current Node REPL session.