1. Home
  2. Node.js
  3. Node.js Basics
  4. Node.js – Console

Node.js – Console

The console is a module pretty similar to the Console provided by the most of the browser for the debugging purpose. It helps developers to debug their application easily by printing the message on the system console. You can use this using one of the following methods.

  • A Console class which provides methods such as console.log(), console.error() and console.warn()
  • A global console instance configured to write to process.stdout and process.stderr.

#1. Using Console Class

The Node.js Console class provides the following methods

  • console.log() – Displays the message on console. This output to stdout.
    > console.log('Hello World!');
    
    Output=>  Hello World!
    
  • console.error() – Same as console.log() function but the output goes to stderr.
    > console.error(new Error('Missing requied parameters'));
    
    Output=> [Error: Missing requied parameters]
    
  • console.warn() – Same as console.log() function, but the output goes to stderr.
    > const name = 'TecAdmin';
    > console.warn(Sorry ${name}!);
    
    Output=> Sorry TecAdmin!