Open In App

Node.js console.info() Method

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 the console.log() method.

Syntax:



console.info(data, args);

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

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



Example 1: The below examples illustrate the use of the console.info() method in Node.js: 

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: The below examples illustrate the use of the console.info() method in Node.js: 

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)
 
let 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


Article Tags :