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:
- data: This parameter specifies the data to be printed.
- args: It is an optional parameter that specifies it to be passed as substitution values in messages 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 new line.
Example 1: The below examples illustrate the use of the console.info() method in Node.js:
Filename: app.js
javascript
// 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
javascript
// 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
Please Login to comment...