• Node.js Video Tutorials

NodeJS - console.info() Method



The Node.js console.info() method of node.js is used to print information to stdout in a new line. It is an alias of the Console.log() method.

Using these two methods we can print the given messages to the standard output stream (stdout) ie. in the terminal or other logging mechanisms, such as a file or network connection. It takes any number of arguments and prints them out separated by spaces with a newline at the end.

Syntax

Following is the syntax of the Node.js console.info() method −

console.info(data, …args);

Parameters

This method will accept two parameters. The same are described below.

  • data − This parameter specifies the message that is going to be printed on the console.

  • args − This is an optional parameter, it holds the substitution values that will be passed to the data.

Return value

This method does not return anything; instead, it prints the formatted information to stdout in a new line similar to the console.log() method.

Example

The Node.js console.info() method works similarly to the console.log() method. This method accepts a parameter (data).

In this example, we are calling console.info() method with only a data parameter.

console.info("Welcome to tutorialspoint");
console.info("Simply Easy Learning at your fingertips");

Output

As we can see in the output, the message we passed as a data parameter is printed to stdout in a new line on the console. Similar to the console.log() method of node.js.

Welcome to tutorialspoint
Simply Easy Learning at your fingertips

Example

The console.info() method of node.js will accept an optional parameter (args).

In this example, we are calling console.info() method with two parameters data and args. We are passing string values as substitution values.

console.info("Welcome to %s", "tutorialspoint");
console.info("Simply %s Learning at %s fingertips", "Easy", "your" );

Output

As we can see in the output, the message we passed as a data parameter and also substitution values in the args parameter is printed to stdout in a newline on the console.

Welcome to tutorialspoint
Simply Easy Learning at your fingertips

Example

In this example, we are calling console.info() method with two parameters data and args. We are passing integer values as substitution values.

console.info("One - %d Two - %d Three - %d", 1, 2, 3);
console.info("Numbers in above statement %d", 3);

Output

As we can see in the output, the message we passed as a data parameter and also the integer substitution values in the args parameter are printed to stdout in a newline on the console.

One - 1 Two - 2 Three - 3
Numbers in above statement 3
nodejs_console_module.htm
Advertisements