Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js console.log vs console.info

People also ask

What is the difference between console info and console log?

Technically console. debug() console.info() and console. log() are identical - the only difference is that debug messages are hidden by default and log messages are visible in the recent versions of Chrome (to see debug messages, you have to set the log level to Verbose in the Devtools).

What is console log in node JS?

Node. js provides a console module which provides tons of very useful ways to interact with the command line. It is basically the same as the console object you find in the browser. The most basic and most used method is console. log() , which prints the string you pass to it to the console.

What is console info js?

The console.info() method outputs an informational message to the Web console. In Firefox, a small "i" icon is displayed next to these items in the Web console's log. Note: This feature is available in Web Workers.

How do I find my console info?

Google Chrome You can also use Option + ⌘ + J (on macOS), or Shift + CTRL + J (on Windows/Linux). The console will either open up within your existing Chrome window, or in a new window. You may have to select the Console tab.


According to the documentation that you linked to, console.error and console.warn outputs to stderr. The others output to stdout.

If you are doing piping or redirection from node.js the difference is important.

There is a lot of JavaScript written to run in both the browser and Node.js. Having node implement the full console allows for greater code cross-compatibility.

In most browsers, not only do these log in different colors, but you can also filter to see specific messages.

console.info("info");
console.error("error");
console.warn("warn");
console.log("log");

While console.log and console.info might not be different, there are other uses except mere coloring. For example, when using a linter like eslint, you can set console.log to provide a warning message. Let's say you only want to use console.log for your development purposes and use console.info for information that end users might need. With a linter you now have a visible and direct reminder of your temporary console.log that aid you during development, but must be removed before commits/publishing.


console.log() is shorter than console.info()

They're the same thing, and that's the only advantage.

enter image description here


According to the docs it's pretty clear.

console.info([data], [...])# Same as console.log.

console.error([data], [...])# Same as console.log but prints to stderr.

console.warn([data], [...])# Same as console.error.

This means there is no benefit or downside. info == log, and warn == error. Unless you want to print to stderr, info and or log will work.


Visually, No difference actually among console.log , console.info , console.warn , as well as console.error regarding the server side(terminal).

However, there are lightweight modules that add blue, orange and red colors for console.info , console.warn , as well as console.error respectively . By that, console API behaves like client-side.

 npm i console-info console-warn console-error --save-dev;

enter image description here