HI WELCOME TO SIRIS

Node.js Console

Leave a Comment
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:
  1. console.log()
  2. console.error()
  3. console.warn()

Node.js console.log()

The console.log() function is used to display simple message on console.
File: console_example1.js
  1. console.log('Hello JavaTpoint');   
Open Node.js command prompt and run the following code:
  1. node console_example1.js  
Node.js console example 1
We can also use format specifier in console.log() function.
File: console_example2.js
  1. console.log('Hello %s''JavaTpoint');   
Open Node.js command prompt and run the following code:
  1. node console_example2.js  
Node.js console example 2

Node.js console.error()

The console.error() function is used to render error message on console.
File: console_example3.js
  1. console.error(new Error('Hell! This is a wrong method.'));  
Open Node.js command prompt and run the following code:
  1. node console_example3.js  
Node.js console example 3

Node.js console.warn()

The console.warn() function is used to display warning message on console.
File: console_example4.js
  1. const name = 'John';  
  2. console.warn(`Don't mess with me ${name}! Don't mess with me!`);   
Open Node.js command prompt and run the following code:
  1. node console_example4.js  
Node.js console example 4

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.