Skip to content
Related Articles

Related Articles

Improve Article

Node.js console.info() Method

  • Last Updated : 06 Jul, 2020

The console.info() method is an inbuilt application programming interface of the console module which is used to print messages to stdout in a newline. It is similar to console.log() method.

Syntax:

console.info(data, args);

Parameters: This method has two parameters as mentioned above and described below:

  • data: This parameter specifies the data to be printed.
  • args: It is optional parameter that specifies it to be passed as substitution values in message passed to data. All passed args are sent to util.format().

Return Value: This method doesn’t return anything but print the formatted message to stdout in a newline.

Below examples illustrate the use of console.info() method in Node.js:



Example 1: Filename: app.js




// Node.js program to demonstrate the   
// console.info() method
  
// Accessing console module
const console = require('console');
   
// Calling console.info() method
console.info("this is a sample info message!");
console.info("sample info message with args: %d", 39);

Run the app.js file using the following command:

node app.js

Output:

this is a sample info message!
sample info message with args: 39

Example 2:
Filename: app.js




// Node.js program to demonstrate the   
// console.info() method
  
// Accessing console module
const console = require('console');
  
// Calling console.info() method
console.info("this is a %s" +
    " sample info message!");
  
console.info("sample info message "
    + "with args: %d", 34);
console.info("info message: Warning "
    + "at function %s: line number"
    + " %d ff()", 96)
  
var isDebugMode = true;
console.custom_info = function (message) {
    if (isDebugMode) {
        console.log(message);
    }
}
  
console.custom_info("custom info message");

Run the app.js file using the following command:

node app.js

Output:

this is a  sample info message!
sample info message with args: 34
info message: Warning at function ff(): line number 96
custom info message

Note: The above program will compile and run by using the node filename.js command.

Reference: https://nodejs.org/api/console.html#console_console_info_data_args




My Personal Notes arrow_drop_up
Recommended Articles
Page :