When we say about the Node.js console, this module will provides a simple debugging console same as JavaScript console mechanism provided by web browsers.
And below are the three console methods which are used to write any node.js stream:-
(1)console.log()
(2)console.error()
(3)console.warn()
(1)Node.js console/log()
We use console.log() function to display simple message on console.
File: console_example.js
console.log('Hello CrackYourInterview');
Now you need to open Node.js command prompt and run the following code to call console_example.js file.
node console_example.js
/>
We can also use format specifier in console.log() function and below is the function and the filename.
File: console_example1.js
console.log('Hello %s','CrackYourInterview');
Now need to open Node.js command prompt and neew to run the below command to execute the file console_example1.js:-
node console_example1.js
(2)Node.js console.error()
Well console.error() function is mainly used to rendor error message on the console.
File: console_example2.js
console.error(new Error('Hi! this is wrong method'));
Now you will open Node.js command prompt and run the follwoing code:
node console_example2.js
(3)Node.js console.warn()
Well console.warn() function is mainly used to display warning message on the console.
File: console_example3.js
const name ='Pau';
console.warn('You are not doing well $(name)! so correct your input!');
Now you need to open Node.js command prompt and run the below code:-
node console_example3.js