I noticed that node.js has both console.error and util.debug, as well as console.log and util.log.
Is there a difference besides the console.* functions being more robust in the parameters they take? The API says that they write to stdout and stderr respectively.
If there’s no difference, which should I use and why?
They’re two different functions, that do two different things. Learn to read the source. It will help you a lot (even in languages like C# with reflector)
Sources
Console
Utils
Log Functions:
Console
Utils
Why
As with every other Unix oriented system, which node is most definitely geared in the guise of – see the many comments from Ryan on the topic, the logging functions are given in the same guise. There are two basic classes for logging, and they both do effectively the same thing, but for different reasons. To the casual observer, they are the same, but they’re not really.
Console logging is intended to be used during debugging. This will go to STDOUT and will show your statements on the REPL1 console, useful for debugging.
Utility logging is intended to be used during standard services runtime. They will goto the process STDOUT, which often is a log file for the process.
But since this can be outwardly overridden at need, and because it will be different in the future (most likely) for Windows processes (given the new ports and developments) and other systems, then you should try to use these methods as the de facto way to write out to the logs during normal runtime. Examples of how it will be different in Windows include the use of the system log for logging, as opposed to a straight logfile.
So how do you know which one you need?
If you’re planning on running this in the REPL for debugging, use the console logger. If you’re intending to start the service and forget about it, then use the utils logging.
1 – Read Evaluate Print Loop