The Node.js console module provides a simple debugging console similar to JavaScript console mechanism provided by web browsers.
There are three console methods that are used to write any node.js stream:
The console.log() function is used to display simple message on console.
File: console_example1.js
console.log('Hello rookienerd');
Open Node.js command prompt and run the following code:
node console_example1.js
We can also use format specifier in console.log() function.
File: console_example2.js
console.log('Hello %s', 'rookienerd');
Open Node.js command prompt and run the following code:
node console_example2.js
The console.error() function is used to render error message on console.
File: console_example3.js
console.error(new Error('Hell! This is a wrong method.'));
Open Node.js command prompt and run the following code:
node console_example3.js
The console.warn() function is used to display warning message on console.
File: console_example4.js
const name = 'John'; console.warn(`Don't mess with me ${name}! Don't mess with me!`);
Open Node.js command prompt and run the following code:
node console_example4.js