learnyounode
Version:
Learn You The Node.js For Much Win! An intro to Node.js via a set of self-guided workshops.
548 lines (529 loc) • 175 kB
HTML
<!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Util | Node.js v12.10.0 Documentation</title>
<link rel="stylesheet" href="data:text/css;base64,LyogbGF0aW4tZXh0ICovCkBmb250LWZhY2UgewogIGZvbnQtZmFtaWx5OiAnTGF0byc7CiAgZm9udC1zdHlsZTogaXRhbGljOwogIGZvbnQtd2VpZ2h0OiA0MDA7CiAgc3JjOiBsb2NhbCgnTGF0byBJdGFsaWMnKSwgbG9jYWwoJ0xhdG8tSXRhbGljJyksIHVybChodHRwczovL2ZvbnRzLmdzdGF0aWMuY29tL3MvbGF0by92MTYvUzZ1OHc0Qk1VVFBIanhzQVVpLXFOaVhnN2VVMC53b2ZmMikgZm9ybWF0KCd3b2ZmMicpOwogIHVuaWNvZGUtcmFuZ2U6IFUrMDEwMC0wMjRGLCBVKzAyNTksIFUrMUUwMC0xRUZGLCBVKzIwMjAsIFUrMjBBMC0yMEFCLCBVKzIwQUQtMjBDRiwgVSsyMTEzLCBVKzJDNjAtMkM3RiwgVStBNzIwLUE3RkY7Cn0KLyogbGF0aW4gKi8KQGZvbnQtZmFjZSB7CiAgZm9udC1mYW1pbHk6ICdMYXRvJzsKICBmb250LXN0eWxlOiBpdGFsaWM7CiAgZm9udC13ZWlnaHQ6IDQwMDsKICBzcmM6IGxvY2FsKCdMYXRvIEl0YWxpYycpLCBsb2NhbCgnTGF0by1JdGFsaWMnKSwgdXJsKGh0dHBzOi8vZm9udHMuZ3N0YXRpYy5jb20vcy9sYXRvL3YxNi9TNnU4dzRCTVVUUEhqeHNBWEMtcU5pWGc3US53b2ZmMikgZm9ybWF0KCd3b2ZmMicpOwogIHVuaWNvZGUtcmFuZ2U6IFUrMDAwMC0wMEZGLCBVKzAxMzEsIFUrMDE1Mi0wMTUzLCBVKzAyQkItMDJCQywgVSswMkM2LCBVKzAy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21tZW50IHsKICBjb2xvcjogIzY2NjsKICBmb250LXdlaWdodDogbGlnaHRlcjsKfQo=">
<link rel="canonical" href="https://nodejs.org/api/util.html">
</head>
<body class="alt apidoc" id="api-section-util">
<div id="content" class="clearfix">
<div id="column2" class="interior">
<div id="intro" class="interior">
<a href="https://nodejs.org/" title="Go back to the home page">
Node.js
</a>
</div>
<ul>
<li><a href="https://nodejs.org/api/documentation.html" class="nav-documentation">About these Docs</a></li>
<li><a href="https://nodejs.org/api/synopsis.html" class="nav-synopsis">Usage & Example</a></li>
</ul>
<div class="line"></div>
<ul>
<li><a href="https://nodejs.org/api/assert.html" class="nav-assert">Assertion Testing</a></li>
<li><a href="https://nodejs.org/api/async_hooks.html" class="nav-async_hooks">Async Hooks</a></li>
<li><a href="https://nodejs.org/api/buffer.html" class="nav-buffer">Buffer</a></li>
<li><a href="https://nodejs.org/api/addons.html" class="nav-addons">C++ Addons</a></li>
<li><a href="https://nodejs.org/api/n-api.html" class="nav-n-api">C/C++ Addons - N-API</a></li>
<li><a href="https://nodejs.org/api/child_process.html" class="nav-child_process">Child Processes</a></li>
<li><a href="https://nodejs.org/api/cluster.html" class="nav-cluster">Cluster</a></li>
<li><a href="https://nodejs.org/api/cli.html" class="nav-cli">Command Line Options</a></li>
<li><a href="https://nodejs.org/api/console.html" class="nav-console">Console</a></li>
<li><a href="https://nodejs.org/api/crypto.html" class="nav-crypto">Crypto</a></li>
<li><a href="https://nodejs.org/api/debugger.html" class="nav-debugger">Debugger</a></li>
<li><a href="https://nodejs.org/api/deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
<li><a href="https://nodejs.org/api/dns.html" class="nav-dns">DNS</a></li>
<li><a href="https://nodejs.org/api/domain.html" class="nav-domain">Domain</a></li>
<li><a href="https://nodejs.org/api/esm.html" class="nav-esm">ECMAScript Modules</a></li>
<li><a href="https://nodejs.org/api/errors.html" class="nav-errors">Errors</a></li>
<li><a href="https://nodejs.org/api/events.html" class="nav-events">Events</a></li>
<li><a href="https://nodejs.org/api/fs.html" class="nav-fs">File System</a></li>
<li><a href="https://nodejs.org/api/globals.html" class="nav-globals">Globals</a></li>
<li><a href="https://nodejs.org/api/http.html" class="nav-http">HTTP</a></li>
<li><a href="https://nodejs.org/api/http2.html" class="nav-http2">HTTP/2</a></li>
<li><a href="https://nodejs.org/api/https.html" class="nav-https">HTTPS</a></li>
<li><a href="https://nodejs.org/api/inspector.html" class="nav-inspector">Inspector</a></li>
<li><a href="https://nodejs.org/api/intl.html" class="nav-intl">Internationalization</a></li>
<li><a href="https://nodejs.org/api/modules.html" class="nav-modules">Modules</a></li>
<li><a href="https://nodejs.org/api/net.html" class="nav-net">Net</a></li>
<li><a href="https://nodejs.org/api/os.html" class="nav-os">OS</a></li>
<li><a href="https://nodejs.org/api/path.html" class="nav-path">Path</a></li>
<li><a href="https://nodejs.org/api/perf_hooks.html" class="nav-perf_hooks">Performance Hooks</a></li>
<li><a href="https://nodejs.org/api/policy.html" class="nav-policy">Policies</a></li>
<li><a href="https://nodejs.org/api/process.html" class="nav-process">Process</a></li>
<li><a href="https://nodejs.org/api/punycode.html" class="nav-punycode">Punycode</a></li>
<li><a href="https://nodejs.org/api/querystring.html" class="nav-querystring">Query Strings</a></li>
<li><a href="https://nodejs.org/api/readline.html" class="nav-readline">Readline</a></li>
<li><a href="https://nodejs.org/api/repl.html" class="nav-repl">REPL</a></li>
<li><a href="https://nodejs.org/api/report.html" class="nav-report">Report</a></li>
<li><a href="https://nodejs.org/api/stream.html" class="nav-stream">Stream</a></li>
<li><a href="https://nodejs.org/api/string_decoder.html" class="nav-string_decoder">String Decoder</a></li>
<li><a href="https://nodejs.org/api/timers.html" class="nav-timers">Timers</a></li>
<li><a href="https://nodejs.org/api/tls.html" class="nav-tls">TLS/SSL</a></li>
<li><a href="https://nodejs.org/api/tracing.html" class="nav-tracing">Trace Events</a></li>
<li><a href="https://nodejs.org/api/tty.html" class="nav-tty">TTY</a></li>
<li><a href="https://nodejs.org/api/dgram.html" class="nav-dgram">UDP/Datagram</a></li>
<li><a href="https://nodejs.org/api/url.html" class="nav-url">URL</a></li>
<li><a href="https://nodejs.org/api/util.html" class="nav-util active">Utilities</a></li>
<li><a href="https://nodejs.org/api/v8.html" class="nav-v8">V8</a></li>
<li><a href="https://nodejs.org/api/vm.html" class="nav-vm">VM</a></li>
<li><a href="https://nodejs.org/api/worker_threads.html" class="nav-worker_threads">Worker Threads</a></li>
<li><a href="https://nodejs.org/api/zlib.html" class="nav-zlib">Zlib</a></li>
</ul>
<div class="line"></div>
<ul>
<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">GitHub Repo & Issue Tracker</a></li>
</ul>
</div>
<div id="column1" data-id="util" class="interior">
<header>
<h1>Node.js v12.10.0 Documentation</h1>
<div id="gtoc">
<ul>
<li>
<a href="https://nodejs.org/api/index.html" name="toc">Index</a>
</li>
<li>
<a href="https://nodejs.org/api/all.html">View on single page</a>
</li>
<li>
<a href="https://nodejs.org/api/util.json">View as JSON</a>
</li>
<li class="version-picker">
<a href="#">View another version <span>▼</span></a>
<ol class="version-picker"><li><a href="https://nodejs.org/docs/latest-v12.x/api/util.html">12.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v11.x/api/util.html">11.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v10.x/api/util.html">10.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v9.x/api/util.html">9.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v8.x/api/util.html">8.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v7.x/api/util.html">7.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v6.x/api/util.html">6.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v5.x/api/util.html">5.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v4.x/api/util.html">4.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/util.html">0.12.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/util.html">0.10.x</a></li></ol>
</li>
<li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/util.md"><span class="github_icon"><svg height="16" width="16" viewBox="0 0 16.1 16.1" fill="currentColor"><path d="M8 0a8 8 0 0 0-2.5 15.6c.4 0 .5-.2.5-.4v-1.5c-2 .4-2.5-.5-2.7-1 0-.1-.5-.9-.8-1-.3-.2-.7-.6 0-.6.6 0 1 .6 1.2.8.7 1.2 1.9 1 2.4.7 0-.5.2-.9.5-1-1.8-.3-3.7-1-3.7-4 0-.9.3-1.6.8-2.2 0-.2-.3-1 .1-2 0 0 .7-.3 2.2.7a7.4 7.4 0 0 1 4 0c1.5-1 2.2-.8 2.2-.8.5 1.1.2 2 .1 2.1.5.6.8 1.3.8 2.2 0 3-1.9 3.7-3.6 4 .3.2.5.7.5 1.4v2.2c0 .2.1.5.5.4A8 8 0 0 0 16 8a8 8 0 0 0-8-8z"></path></svg></span>Edit on GitHub</a></li>
</ul>
</div>
<hr>
</header>
<div id="toc">
<h2>Table of Contents</h2>
<ul>
<li>
<p><span class="stability_2"><a href="#util_util">Util</a></span></p>
<ul>
<li><a href="#util_util_callbackify_original">util.callbackify(original)</a></li>
<li><a href="#util_util_debuglog_section">util.debuglog(section)</a></li>
<li><a href="#util_util_deprecate_fn_msg_code">util.deprecate(fn, msg[, code])</a></li>
<li><a href="#util_util_format_format_args">util.format(format[, ...args])</a></li>
<li><a href="#util_util_formatwithoptions_inspectoptions_format_args">util.formatWithOptions(inspectOptions, format[, ...args])</a></li>
<li><a href="#util_util_getsystemerrorname_err">util.getSystemErrorName(err)</a></li>
<li><a href="#util_util_inherits_constructor_superconstructor">util.inherits(constructor, superConstructor)</a></li>
<li><a href="#util_util_inspect_object_options">util.inspect(object[, options])</a></li>
<li>
<p><a href="#util_util_inspect_object_showhidden_depth_colors">util.inspect(object[, showHidden[, depth[, colors]]])</a></p>
<ul>
<li><a href="#util_customizing_util_inspect_colors">Customizing <code>util.inspect</code> colors</a></li>
<li><a href="#util_custom_inspection_functions_on_objects">Custom inspection functions on Objects</a></li>
<li><a href="#util_util_inspect_custom">util.inspect.custom</a></li>
<li><a href="#util_util_inspect_defaultoptions">util.inspect.defaultOptions</a></li>
</ul>
</li>
<li><a href="#util_util_isdeepstrictequal_val1_val2">util.isDeepStrictEqual(val1, val2)</a></li>
<li>
<p><a href="#util_util_promisify_original">util.promisify(original)</a></p>
<ul>
<li><a href="#util_custom_promisified_functions">Custom promisified functions</a></li>
<li><a href="#util_util_promisify_custom">util.promisify.custom</a></li>
</ul>
</li>
<li>
<p><a href="#util_class_util_textdecoder">Class: util.TextDecoder</a></p>
<ul>
<li>
<p><a href="#util_whatwg_supported_encodings">WHATWG Supported Encodings</a></p>
<ul>
<li><a href="#util_encodings_supported_without_icu">Encodings Supported Without ICU</a></li>
<li><a href="#util_encodings_supported_by_default_with_icu">Encodings Supported by Default (With ICU)</a></li>
<li><a href="#util_encodings_requiring_full_icu_data">Encodings Requiring Full ICU Data</a></li>
</ul>
</li>
<li><a href="#util_new_textdecoder_encoding_options">new TextDecoder([encoding[, options]])</a></li>
<li><a href="#util_textdecoder_decode_input_options">textDecoder.decode([input[, options]])</a></li>
<li><a href="#util_textdecoder_encoding">textDecoder.encoding</a></li>
<li><a href="#util_textdecoder_fatal">textDecoder.fatal</a></li>
<li><a href="#util_textdecoder_ignorebom">textDecoder.ignoreBOM</a></li>
</ul>
</li>
<li>
<p><a href="#util_class_util_textencoder">Class: util.TextEncoder</a></p>
<ul>
<li><a href="#util_textencoder_encode_input">textEncoder.encode([input])</a></li>
<li><a href="#util_textencoder_encoding">textEncoder.encoding</a></li>
</ul>
</li>
<li>
<p><a href="#util_util_types">util.types</a></p>
<ul>
<li><a href="#util_util_types_isanyarraybuffer_value">util.types.isAnyArrayBuffer(value)</a></li>
<li><a href="#util_util_types_isargumentsobject_value">util.types.isArgumentsObject(value)</a></li>
<li><a href="#util_util_types_isarraybuffer_value">util.types.isArrayBuffer(value)</a></li>
<li><a href="#util_util_types_isasyncfunction_value">util.types.isAsyncFunction(value)</a></li>
<li><a href="#util_util_types_isbigint64array_value">util.types.isBigInt64Array(value)</a></li>
<li><a href="#util_util_types_isbiguint64array_value">util.types.isBigUint64Array(value)</a></li>
<li><a href="#util_util_types_isbooleanobject_value">util.types.isBooleanObject(value)</a></li>
<li><a href="#util_util_types_isboxedprimitive_value">util.types.isBoxedPrimitive(value)</a></li>
<li><a href="#util_util_types_isdataview_value">util.types.isDataView(value)</a></li>
<li><a href="#util_util_types_isdate_value">util.types.isDate(value)</a></li>
<li><a href="#util_util_types_isexternal_value">util.types.isExternal(value)</a></li>
<li><a href="#util_util_types_isfloat32array_value">util.types.isFloat32Array(value)</a></li>
<li><a href="#util_util_types_isfloat64array_value">util.types.isFloat64Array(value)</a></li>
<li><a href="#util_util_types_isgeneratorfunction_value">util.types.isGeneratorFunction(value)</a></li>
<li><a href="#util_util_types_isgeneratorobject_value">util.types.isGeneratorObject(value)</a></li>
<li><a href="#util_util_types_isint8array_value">util.types.isInt8Array(value)</a></li>
<li><a href="#util_util_types_isint16array_value">util.types.isInt16Array(value)</a></li>
<li><a href="#util_util_types_isint32array_value">util.types.isInt32Array(value)</a></li>
<li><a href="#util_util_types_ismap_value">util.types.isMap(value)</a></li>
<li><a href="#util_util_types_ismapiterator_value">util.types.isMapIterator(value)</a></li>
<li><a href="#util_util_types_ismodulenamespaceobject_value">util.types.isModuleNamespaceObject(value)</a></li>
<li><a href="#util_util_types_isnativeerror_value">util.types.isNativeError(value)</a></li>
<li><a href="#util_util_types_isnumberobject_value">util.types.isNumberObject(value)</a></li>
<li><a href="#util_util_types_ispromise_value">util.types.isPromise(value)</a></li>
<li><a href="#util_util_types_isproxy_value">util.types.isProxy(value)</a></li>
<li><a href="#util_util_types_isregexp_value">util.types.isRegExp(value)</a></li>
<li><a href="#util_util_types_isset_value">util.types.isSet(value)</a></li>
<li><a href="#util_util_types_issetiterator_value">util.types.isSetIterator(value)</a></li>
<li><a href="#util_util_types_issharedarraybuffer_value">util.types.isSharedArrayBuffer(value)</a></li>
<li><a href="#util_util_types_isstringobject_value">util.types.isStringObject(value)</a></li>
<li><a href="#util_util_types_issymbolobject_value">util.types.isSymbolObject(value)</a></li>
<li><a href="#util_util_types_istypedarray_value">util.types.isTypedArray(value)</a></li>
<li><a href="#util_util_types_isuint8array_value">util.types.isUint8Array(value)</a></li>
<li><a href="#util_util_types_isuint8clampedarray_value">util.types.isUint8ClampedArray(value)</a></li>
<li><a href="#util_util_types_isuint16array_value">util.types.isUint16Array(value)</a></li>
<li><a href="#util_util_types_isuint32array_value">util.types.isUint32Array(value)</a></li>
<li><a href="#util_util_types_isweakmap_value">util.types.isWeakMap(value)</a></li>
<li><a href="#util_util_types_isweakset_value">util.types.isWeakSet(value)</a></li>
<li><a href="#util_util_types_iswebassemblycompiledmodule_value">util.types.isWebAssemblyCompiledModule(value)</a></li>
</ul>
</li>
<li>
<p><a href="#util_deprecated_apis">Deprecated APIs</a></p>
<ul>
<li><span class="stability_0"><a href="#util_util_extend_target_source">util._extend(target, source)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isarray_object">util.isArray(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isboolean_object">util.isBoolean(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isbuffer_object">util.isBuffer(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isdate_object">util.isDate(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_iserror_object">util.isError(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isfunction_object">util.isFunction(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isnull_object">util.isNull(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isnullorundefined_object">util.isNullOrUndefined(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isnumber_object">util.isNumber(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isobject_object">util.isObject(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isprimitive_object">util.isPrimitive(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isregexp_object">util.isRegExp(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isstring_object">util.isString(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_issymbol_object">util.isSymbol(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isundefined_object">util.isUndefined(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_log_string">util.log(string)</a></span></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div id="apicontent">
<h1>Util<span><a class="mark" href="#util_util" id="util_util">#</a></span></h1>
<p></p><div class="api_stability api_stability_2"><a href="https://nodejs.org/api/documentation.html#documentation_stability_index">Stability: 2</a> - Stable</div><p></p>
<p>The <code>util</code> module is primarily designed to support the needs of Node.js' own
internal APIs. However, many of the utilities are useful for application and
module developers as well. It can be accessed using:</p>
<pre><code class="language-js">const util = require('util');
</code></pre>
<h2>util.callbackify(original)<a class="srclink" href="https://github.com/nodejs/node/blob/3a2e75d9a5c31d20e429d505b82dd182e33f459a/lib/util.js#L183">[src]</a><span><a class="mark" href="#util_util_callbackify_original" id="util_util_callbackify_original">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v8.2.0</span>
</div>
<ul>
<li><code>original</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> An <code>async</code> function</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> a callback style function</li>
</ul>
<p>Takes an <code>async</code> function (or a function that returns a <code>Promise</code>) and returns a
function following the error-first callback style, i.e. taking
an <code>(err, value) => ...</code> callback as the last argument. In the callback, the
first argument will be the rejection reason (or <code>null</code> if the <code>Promise</code>
resolved), and the second argument will be the resolved value.</p>
<pre><code class="language-js">const util = require('util');
async function fn() {
return 'hello world';
}
const callbackFunction = util.callbackify(fn);
callbackFunction((err, ret) => {
if (err) throw err;
console.log(ret);
});
</code></pre>
<p>Will print:</p>
<pre><code class="language-txt">hello world
</code></pre>
<p>The callback is executed asynchronously, and will have a limited stack trace.
If the callback throws, the process will emit an <a href="https://nodejs.org/api/process.html#process_event_uncaughtexception"><code>'uncaughtException'</code></a>
event, and if not handled will exit.</p>
<p>Since <code>null</code> has a special meaning as the first argument to a callback, if a
wrapped function rejects a <code>Promise</code> with a falsy value as a reason, the value
is wrapped in an <code>Error</code> with the original value stored in a field named
<code>reason</code>.</p>
<pre><code class="language-js">function fn() {
return Promise.reject(null);
}
const callbackFunction = util.callbackify(fn);
callbackFunction((err, ret) => {
// When the Promise was rejected with `null` it is wrapped with an Error and
// the original value is stored in `reason`.
err && err.hasOwnProperty('reason') && err.reason === null; // true
});
</code></pre>
<h2>util.debuglog(section)<span><a class="mark" href="#util_util_debuglog_section" id="util_util_debuglog_section">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.11.3</span>
</div>
<ul>
<li><code>section</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A string identifying the portion of the application for
which the <code>debuglog</code> function is being created.</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> The logging function</li>
</ul>
<p>The <code>util.debuglog()</code> method is used to create a function that conditionally
writes debug messages to <code>stderr</code> based on the existence of the <code>NODE_DEBUG</code>
environment variable. If the <code>section</code> name appears within the value of that
environment variable, then the returned function operates similar to
<a href="https://nodejs.org/api/console.html#console_console_error_data_args"><code>console.error()</code></a>. If not, then the returned function is a no-op.</p>
<pre><code class="language-js">const util = require('util');
const debuglog = util.debuglog('foo');
debuglog('hello from foo [%d]', 123);
</code></pre>
<p>If this program is run with <code>NODE_DEBUG=foo</code> in the environment, then
it will output something like:</p>
<pre><code class="language-txt">FOO 3245: hello from foo [123]
</code></pre>
<p>where <code>3245</code> is the process id. If it is not run with that
environment variable set, then it will not print anything.</p>
<p>The <code>section</code> supports wildcard also:</p>
<pre><code class="language-js">const util = require('util');
const debuglog = util.debuglog('foo-bar');
debuglog('hi there, it\'s foo-bar [%d]', 2333);
</code></pre>
<p>if it is run with <code>NODE_DEBUG=foo*</code> in the environment, then it will output
something like:</p>
<pre><code class="language-txt">FOO-BAR 3257: hi there, it's foo-bar [2333]
</code></pre>
<p>Multiple comma-separated <code>section</code> names may be specified in the <code>NODE_DEBUG</code>
environment variable: <code>NODE_DEBUG=fs,net,tls</code>.</p>
<h2>util.deprecate(fn, msg[, code])<span><a class="mark" href="#util_util_deprecate_fn_msg_code" id="util_util_deprecate_fn_msg_code">#</a></span></h2>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v10.0.0</td>
<td><p>Deprecation warnings are only emitted once for each code.</p></td></tr>
<tr><td>v0.8.0</td>
<td><p><span>Added in: v0.8.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>fn</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> The function that is being deprecated.</li>
<li><code>msg</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A warning message to display when the deprecated function is
invoked.</li>
<li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A deprecation code. See the <a href="https://nodejs.org/api/deprecations.html#deprecations_list_of_deprecated_apis">list of deprecated APIs</a> for a
list of codes.</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> The deprecated function wrapped to emit a warning.</li>
</ul>
<p>The <code>util.deprecate()</code> method wraps <code>fn</code> (which may be a function or class) in
such a way that it is marked as deprecated.</p>
<pre><code class="language-js">const util = require('util');
exports.obsoleteFunction = util.deprecate(() => {
// Do something here.
}, 'obsoleteFunction() is deprecated. Use newShinyFunction() instead.');
</code></pre>
<p>When called, <code>util.deprecate()</code> will return a function that will emit a
<code>DeprecationWarning</code> using the <a href="https://nodejs.org/api/process.html#process_event_warning"><code>'warning'</code></a> event. The warning will
be emitted and printed to <code>stderr</code> the first time the returned function is
called. After the warning is emitted, the wrapped function is called without
emitting a warning.</p>
<p>If the same optional <code>code</code> is supplied in multiple calls to <code>util.deprecate()</code>,
the warning will be emitted only once for that <code>code</code>.</p>
<pre><code class="language-js">const util = require('util');
const fn1 = util.deprecate(someFunction, someMessage, 'DEP0001');
const fn2 = util.deprecate(someOtherFunction, someOtherMessage, 'DEP0001');
fn1(); // Emits a deprecation warning with code DEP0001
fn2(); // Does not emit a deprecation warning because it has the same code
</code></pre>
<p>If either the <code>--no-deprecation</code> or <code>--no-warnings</code> command line flags are
used, or if the <code>process.noDeprecation</code> property is set to <code>true</code> <em>prior</em> to
the first deprecation warning, the <code>util.deprecate()</code> method does nothing.</p>
<p>If the <code>--trace-deprecation</code> or <code>--trace-warnings</code> command line flags are set,
or the <code>process.traceDeprecation</code> property is set to <code>true</code>, a warning and a
stack trace are printed to <code>stderr</code> the first time the deprecated function is
called.</p>
<p>If the <code>--throw-deprecation</code> command line flag is set, or the
<code>process.throwDeprecation</code> property is set to <code>true</code>, then an exception will be
thrown when the deprecated function is called.</p>
<p>The <code>--throw-deprecation</code> command line flag and <code>process.throwDeprecation</code>
property take precedence over <code>--trace-deprecation</code> and
<code>process.traceDeprecation</code>.</p>
<h2>util.format(format[, ...args])<span><a class="mark" href="#util_util_format_format_args" id="util_util_format_format_args">#</a></span></h2>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v12.0.0</td>
<td><p>The <code>format</code> argument is now only taken as such if it actually contains format specifiers.</p></td></tr>
<tr><td>v12.0.0</td>
<td><p>If the <code>format</code> argument is not a format string, the output string's formatting is no longer dependent on the type of the first argument. This change removes previously present quotes from strings that were being output when the first argument was not a string.</p></td></tr>
<tr><td>v11.4.0</td>
<td><p>The <code>%d</code>, <code>%f</code> and <code>%i</code> specifiers now support Symbols properly.</p></td></tr>
<tr><td>v11.4.0</td>
<td><p>The <code>%o</code> specifier's <code>depth</code> has default depth of 4 again.</p></td></tr>
<tr><td>v11.0.0</td>
<td><p>The <code>%o</code> specifier's <code>depth</code> option will now fall back to the default depth.</p></td></tr>
<tr><td>v10.12.0</td>
<td><p>The <code>%d</code> and <code>%i</code> specifiers now support BigInt.</p></td></tr>
<tr><td>v8.4.0</td>
<td><p>The <code>%o</code> and <code>%O</code> specifiers are supported now.</p></td></tr>
<tr><td>v0.5.3</td>
<td><p><span>Added in: v0.5.3</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>format</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A <code>printf</code>-like format string.</li>
</ul>
<p>The <code>util.format()</code> method returns a formatted string using the first argument
as a <code>printf</code>-like format string which can contain zero or more format
specifiers. Each specifier is replaced with the converted value from the
corresponding argument. Supported specifiers are:</p>
<ul>
<li><code>%s</code> - <code>String</code> will be used to convert all values except <code>BigInt</code>, <code>Object</code>
and <code>-0</code>. <code>BigInt</code> values will be represented with an <code>n</code> and Objects that
have no user defined <code>toString</code> function are inspected using <code>util.inspect()</code>
with options <code>{ depth: 0, colors: false, compact: 3 }</code>.</li>
<li><code>%d</code> - <code>Number</code> will be used to convert all values except <code>BigInt</code> and
<code>Symbol</code>.</li>
<li><code>%i</code> - <code>parseInt(value, 10)</code> is used for all values except <code>BigInt</code> and
<code>Symbol</code>.</li>
<li><code>%f</code> - <code>parseFloat(value)</code> is used for all values expect <code>Symbol</code>.</li>
<li><code>%j</code> - JSON. Replaced with the string <code>'[Circular]'</code> if the argument contains
circular references.</li>
<li><code>%o</code> - <code>Object</code>. A string representation of an object with generic JavaScript
object formatting. Similar to <code>util.inspect()</code> with options
<code>{ showHidden: true, showProxy: true }</code>. This will show the full object
including non-enumerable properties and proxies.</li>
<li><code>%O</code> - <code>Object</code>. A string representation of an object with generic JavaScript
object formatting. Similar to <code>util.inspect()</code> without options. This will show
the full object not including non-enumerable properties and proxies.</li>
<li><code>%%</code> - single percent sign (<code>'%'</code>). This does not consume an argument.</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> The formatted string</li>
</ul>
<p>If a specifier does not have a corresponding argument, it is not replaced:</p>
<pre><code class="language-js">util.format('%s:%s', 'foo');
// Returns: 'foo:%s'
</code></pre>
<p>Values that are not part of the format string are formatted using
<code>util.inspect()</code> if their type is not <code>string</code>.</p>
<p>If there are more arguments passed to the <code>util.format()</code> method than the
number of specifiers, the extra arguments are concatenated to the returned
string, separated by spaces:</p>
<pre><code class="language-js">util.format('%s:%s', 'foo', 'bar', 'baz');
// Returns: 'foo:bar baz'
</code></pre>
<p>If the first argument does not contain a valid format specifier, <code>util.format()</code>
returns a string that is the concatenation of all arguments separated by spaces:</p>
<pre><code class="language-js">util.format(1, 2, 3);
// Returns: '1 2 3'
</code></pre>
<p>If only one argument is passed to <code>util.format()</code>, it is returned as it is
without any formatting:</p>
<pre><code class="language-js">util.format('%% %s');
// Returns: '%% %s'
</code></pre>
<p><code>util.format()</code> is a synchronous method that is intended as a debugging tool.
Some input values can have a significant performance overhead that can block the
event loop. Use this function with care and never in a hot code path.</p>
<h2>util.formatWithOptions(inspectOptions, format[, ...args])<span><a class="mark" href="#util_util_formatwithoptions_inspectoptions_format_args" id="util_util_formatwithoptions_inspectoptions_format_args">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div>
<ul>
<li><code>inspectOptions</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li>
<li><code>format</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>This function is identical to <a href="#util_util_format_format_args"><code>util.format()</code></a>, except in that it takes
an <code>inspectOptions</code> argument which specifies options that are passed along to
<a href="#util_util_inspect_object_options"><code>util.inspect()</code></a>.</p>
<pre><code class="language-js">util.formatWithOptions({ colors: true }, 'See object %O', { foo: 42 });
// Returns 'See object { foo: 42 }', where `42` is colored as a number
// when printed to a terminal.
</code></pre>
<h2>util.getSystemErrorName(err)<a class="srclink" href="https://github.com/nodejs/node/blob/3a2e75d9a5c31d20e429d505b82dd182e33f459a/lib/util.js#L217">[src]</a><span><a class="mark" href="#util_util_getsystemerrorname_err" id="util_util_getsystemerrorname_err">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v9.7.0</span>
</div>
<ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>Returns the string name for a numeric error code that comes from a Node.js API.
The mapping between error codes and error names is platform-dependent.
See <a href="https://nodejs.org/api/errors.html#errors_common_system_errors">Common System Errors</a> for the names of common errors.</p>
<pre><code class="language-js">fs.access('file/that/does/not/exist', (err) => {
const name = util.getSystemErrorName(err.errno);
console.error(name); // ENOENT
});
</code></pre>
<h2>util.inherits(constructor, superConstructor)<a class="srclink" href="https://github.com/nodejs/node/blob/3a2e75d9a5c31d20e429d505b82dd182e33f459a/lib/util.js#L140">[src]</a><span><a class="mark" href="#util_util_inherits_constructor_superconstructor" id="util_util_inherits_constructor_superconstructor">#</a></span></h2>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v5.0.0</td>
<td><p>The <code>constructor</code> parameter can refer to an ES6 class now.</p></td></tr>
<tr><td>v0.3.0</td>
<td><p><span>Added in: v0.3.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>constructor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li>
<li><code>superConstructor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li>
</ul>
<p>Usage of <code>util.inherits()</code> is discouraged. Please use the ES6 <code>class</code> and
<code>extends</code> keywords to get language level inheritance support. Also note
that the two styles are <a href="https://github.com/nodejs/node/issues/4179">semantically incompatible</a>.</p>
<p>Inherit the prototype methods from one <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor">constructor</a> into another. The
prototype of <code>constructor</code> will be set to a new object created from
<code>superConstructor</code>.</p>
<p>This mainly adds some input validation on top of
<code>Object.setPrototypeOf(constructor.prototype, superConstructor.prototype)</code>.
As an additional convenience, <code>superConstructor</code> will be accessible
through the <code>constructor.super_</code> property.</p>
<pre><code class="language-js">const util = require('util');
const EventEmitter = require('events');
function MyStream() {
EventEmitter.call(this);
}
util.inherits(MyStream, EventEmitter);
MyStream.prototype.write = function(data) {
this.emit('data', data);
};
const stream = new MyStream();
console.log(stream instanceof EventEmitter); // true
console.log(MyStream.super_ === EventEmitter); // true
stream.on('data', (data) => {
console.log(`Received data: "${data}"`);
});
stream.write('It works!'); // Received data: "It works!"
</code></pre>
<p>ES