A useful feature of the util
module is the ability to write data out to stdout
and stderr
synchronously, which means blocking the process until the data is written out. This allows you to ensure that when the data is written, the system wasn’t in the act of changing it.
To synchronously write data out, you can use one of the following calls, each of which blocks the process until the write completes:
util.debug(string): Writes the string
out to stderr
.
util.error([...]): Accepts multiple arguments and writes them out to stderr
. For example:
util.error(errorCode, "errorname");
util.puts([...]): Accepts multiple arguments and writes them out to stdout
.
util.print([...]): Accepts multiple arguments, converts each one to a string, and then writes them out to stdout
.
util.log(string): Writes the string
out to stdout
, along with a timestamp. For example:
util.log('Some message.'), // 30 Nov 13:26:20 - Some message.