• Node.js Video Tutorials

NodeJS - console.debug() Method



The Node.js console.debug() function is used to print information to stdout in a new line. It works the same as the console.log() method of node.js. This is useful for troubleshooting or understanding how a particular section of code works. Now let's look into the syntax of the console.debug() method.

The Node.js console.debug() of node.js is an inbuilt method of the Console class.

Syntax

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

console.debug(data, args);

Parameters

This method accepts two parameters. The same are described below.

  • data − This parameter specifies the information that print on the screen.

  • args − This is an optional parameter, where args are passed as substitution values in information passed to data. These args can be accessed by format specifiers.

Return value

This method will 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.debug() method works similarly to the Node.js console.log() method. This method accepts a parameter (data).

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

const console = require('console');
console.debug('Tutorialspoint');
console.debug('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. Similar to the console.log() method of node.js.

Tutorialspoint
Simply Easy Learning at your fingertips...

Example

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

In this example, we are calling the console.debug() method with two parameters data and args.

const console = require('console');
console.debug('There are %d pancakes in the refrigerator, 4);
console.debug('%s is having a %d pack body', "Nik", 6);

Output

home/cg/root/63a00e1fdca8a/main.js:3
console.debug('There are %d pancakes in the refrigerator, 4);
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   
SyntaxError: Invalid or unexpected token
   at new Script (vm.js:74:7)
   at createScript (vm.js:246:10)
   at Object.runInThisContext (vm.js:298:10)
   at Module._compile (internal/modules/cjs/loader.js:670:28)
   at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
   at Module.load (internal/modules/cjs/loader.js:612:32)
   at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
   at Function.Module._load (internal/modules/cjs/loader.js:543:3)
   at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
   at startup (internal/bootstrap/node.js:238:19)

Note − To get the accurate result, better execute the above code in local.

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

There are 4 pancakes in the refrigerator
Nik is having a 6 pack body
nodejs_console_module.htm
Advertisements