- Sep 30, 2018
- admin
- 0
Node.js Console:
To write a stream, Node.js supports three console methods:
● Node.js console.log():
Used to display simple message on console.
Syntax:
console.log(message);
● Node.js console.error():
Used to render error message on console.
Syntax:
console.error ( new Error (message));
- js console.warn():
Used to display warning message on console.
Syntax:
console.warn(message);
Node.js REPL:
REPL abbreviates for Read Eval Print and Loop which means reading user input, evaluating the data, printing the result and looping the command. In Node.js, REPL specifies a console or a shell that responds in an interactive mode.
● Starting REPL in Windows:
Run “node” on the Windows command prompt.
● Starting REPL in Linux:
Run “nodejs” on the Linux Terminal.
● Exit REPL:
Press ctrl + c twice.
Writing javascript code in a REPL interactive shell is useful for immediate testing of code with no stress of writing and saving the code in a file. However, this method is suitable only for testing purpose and for small codes.
Node.js REPL Commands:
Some of the important REPL commands are listed below:
COMMANDS | USES |
ctrl + c | To terminate the current command. |
ctrl + c twice | To terminate the node REPL. |
ctrl + d | To terminate the node REPL. |
up/down keys | To see command history and modify previous commands. |
tab keys | To specify the list of current command. |
.help | To specify the list of all commands. |
.break | To exit from multi-line expressions. |
.clear | To exit from multi-line expressions. |
.save filename | To save current node REPL session to a file. |
.load filename | To load file content in current node REPL session. |
Example: Example of Node.js console.log()
console.log(‘Hello Tech Tutorialz!’);
OUTPUT:
Hello Tech Tutorialz!