Namespace node.util
These functions are in the module 'util'
. Use require('util')
to access
them.
- Defined in: node.util.js
Method Summary
Method Attributes | Method Name and Description |
---|---|
static |
node.util.debug(x)
A synchronous output function.
|
static |
node.util.error(x)
|
static |
node.util.exec()
|
static |
node.util.inherits(ctor, superCtor)
Inherit the prototype methods from one
constructor
into another.
|
static |
node.util.inspect(obj, showHidden, depth, colors)
Return a string representation of
object , which is useful for debugging. |
static |
node.util.log(msg)
Output with timestamp on
stdout . |
static |
node.util.p()
|
static |
node.util.print()
|
static |
node.util.pump(readStream, writeStream, callback)
Experimental
Read the data from
readableStream and send it to the writableStream . |
static |
node.util.puts()
|
Method Detail
-
static node.util.debug(x)A synchronous output function. Will block the process and output
string
immediately tostderr
.require('util').debug('message on stderr');
- Parameters:
- {string} x
-
static node.util.error(x)
- Parameters:
- {string} x
-
static node.util.exec()
-
static node.util.inherits(ctor, superCtor)Inherit the prototype methods from one constructor into another. The prototype of
constructor
will be set to a new object created fromsuperConstructor
. As an additional convenience,superConstructor
will be accessible through theconstructor.super
property.var util = require("util"); var events = require("events"); function MyStream() { events.EventEmitter.call(this); } util.inherits(MyStream, events.EventEmitter); MyStream.prototype.write = function(data) { this.emit("data", data); } var stream = new MyStream(); console.log(stream instanceof events.EventEmitter); // true console.log(MyStream.super_ === events.EventEmitter); // true stream.on("data", function(data) { console.log('Received data: "' + data + '"'); }) stream.write("It works!"); // Received data: "It works!"
- Parameters:
- {Function} ctor
- {Function} superCtor
-
static node.util.inspect(obj, showHidden, depth, colors)Return a string representation of
object
, which is useful for debugging. IfshowHidden
istrue
, then the object's non-enumerable properties will be shown too. Ifdepth
is provided, it tellsinspect
how many times to recurse while formatting the object. This is useful for inspecting large complicated objects. The default is to only recurse twice. To make it recurse indefinitely, pass innull
fordepth
. Example of inspecting all properties of theutil
object:var util = require('util'); console.log(util.inspect(util, true, null));
- Parameters:
- {Object} obj
- {string} showHidden
- {number} depth
- {string} colors
-
static node.util.log(msg)Output with timestamp on
stdout
.require('util').log('Timestmaped message.');
- Parameters:
- {string} msg
-
static node.util.p()
-
static node.util.print()
-
static node.util.pump(readStream, writeStream, callback)Experimental Read the data from
readableStream
and send it to thewritableStream
. WhenwritableStream.write(data)
returnsfalse
readableStream
will be paused until thedrain
event occurs on thewritableStream
.callback
gets an error as its only argument and is called whenwritableStream
is closed or when an error occurs.- Parameters:
- {node.stream.Stream} readStream
- {node.stream.Stream} writeStream
- {function(Error?|...[*]):undefined=} callback
-
static node.util.puts()