Skip to content

Instantly share code, notes, and snippets.

@rubys
Created July 3, 2018 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubys/ee71a58c51dbf576aeb63bd210f81f36 to your computer and use it in GitHub Desktop.
Save rubys/ee71a58c51dbf576aeb63bd210f81f36 to your computer and use it in GitHub Desktop.
This file has been truncated, but you can view the full file.
{
"miscs": [
{
"textRaw": "About this Documentation",
"name": "About this Documentation",
"introduced_in": "v0.10.0",
"type": "misc",
"desc": "<p>The goal of this documentation is to comprehensively explain the Node.js\nAPI, both from a reference as well as a conceptual point of view. Each\nsection describes a built-in module or high-level concept.</p>\n<p>Where appropriate, property types, method arguments, and the arguments\nprovided to event handlers are detailed in a list underneath the topic\nheading.</p>\n",
"miscs": [
{
"textRaw": "Contributing",
"name": "contributing",
"desc": "<p>If errors are found in this documentation, please <a href=\"https://github.com/nodejs/node/issues/new\">submit an issue</a>\nor see <a href=\"https://github.com/nodejs/node/blob/master/CONTRIBUTING.md\">the contributing guide</a> for directions on how to submit a patch.</p>\n<p>Every file is generated based on the corresponding <code>.md</code> file in the\n<code>doc/api/</code> folder in Node.js&#39;s source tree. The documentation is generated\nusing the <code>tools/doc/generate.js</code> program. An HTML template is located at\n<code>doc/template.html</code>.</p>\n",
"type": "misc",
"displayName": "Contributing"
},
{
"textRaw": "Stability Index",
"name": "Stability Index",
"type": "misc",
"desc": "<p>Throughout the documentation are indications of a section&#39;s\nstability. The Node.js API is still somewhat changing, and as it\nmatures, certain parts are more reliable than others. Some are so\nproven, and so relied upon, that they are unlikely to ever change at\nall. Others are brand new and experimental, or known to be hazardous\nand in the process of being redesigned.</p>\n<p>The stability indices are as follows:</p>\n<blockquote>\n<p>Stability: 0 - Deprecated. This feature is known to be problematic, and\nchanges may be planned. Do not rely on it. Use of the feature may cause\nwarnings to be emitted. Backwards compatibility across major versions should\nnot be expected.</p>\n</blockquote>\n<!-- separator -->\n<blockquote>\n<p>Stability: 1 - Experimental. This feature is still under active development\nand subject to non-backwards compatible changes, or even removal, in any\nfuture version. Use of the feature is not recommended in production\nenvironments. Experimental features are not subject to the Node.js Semantic\nVersioning model.</p>\n</blockquote>\n<!-- separator -->\n<blockquote>\n<p>Stability: 2 - Stable. The API has proven satisfactory. Compatibility with the\nnpm ecosystem is a high priority, and will not be broken unless absolutely\nnecessary.</p>\n</blockquote>\n<p>Caution must be used when making use of <code>Experimental</code> features, particularly\nwithin modules that may be used as dependencies (or dependencies of\ndependencies) within a Node.js application. End users may not be aware that\nexperimental features are being used, and therefore may experience unexpected\nfailures or behavior changes when API modifications occur. To help avoid such\nsurprises, <code>Experimental</code> features may require a command-line flag to\nexplicitly enable them, or may cause a process warning to be emitted.\nBy default, such warnings are printed to <a href=\"process.html#process_process_stderr\"><code>stderr</code></a> and may be handled by\nattaching a listener to the <a href=\"process.html#process_event_warning\"><code>&#39;warning&#39;</code></a> event.</p>\n"
},
{
"textRaw": "JSON Output",
"name": "json_output",
"meta": {
"added": [
"v0.6.12"
],
"changes": []
},
"stability": 1,
"stabilityText": "Experimental",
"desc": "<p>Every <code>.html</code> document has a corresponding <code>.json</code> document presenting\nthe same information in a structured manner. This feature is\nexperimental, and added for the benefit of IDEs and other utilities that\nwish to do programmatic things with the documentation.</p>\n",
"type": "misc",
"displayName": "JSON Output"
},
{
"textRaw": "Syscalls and man pages",
"name": "syscalls_and_man_pages",
"desc": "<p>System calls like open(2) and read(2) define the interface between user programs\nand the underlying operating system. Node.js functions\nwhich simply wrap a syscall,\nlike <a href=\"fs.html#fs_fs_open_path_flags_mode_callback\"><code>fs.open()</code></a>, will document that. The docs link to the corresponding man\npages (short for manual pages) which describe how the syscalls work.</p>\n<p>Most Unix syscalls have Windows equivalents, but behavior may differ on Windows\nrelative to Linux and macOS. For an example of the subtle ways in which it&#39;s\nsometimes impossible to replace Unix syscall semantics on Windows, see <a href=\"https://github.com/nodejs/node/issues/4760\">Node\nissue 4760</a>.</p>\n",
"type": "misc",
"displayName": "Syscalls and man pages"
}
]
},
{
"textRaw": "Usage",
"name": "Usage",
"introduced_in": "v0.10.0",
"type": "misc",
"desc": "<p><code>node [options] [V8 options] [script.js | -e &quot;script&quot; | - ] [arguments]</code></p>\n<p>Please see the <a href=\"cli.html#cli_command_line_options\">Command Line Options</a> document for information about\ndifferent options and ways to run scripts with Node.js.</p>\n<h2>Example</h2>\n<p>An example of a <a href=\"http.html\">web server</a> written with Node.js which responds with\n<code>&#39;Hello World!&#39;</code>:</p>\n<p>Commands displayed in this document are shown starting with <code>$</code> or <code>&gt;</code>\nto replicate how they would appear in a user&#39;s terminal.\nDo not include the <code>$</code> and <code>&gt;</code> character they are there to\nindicate the start of each command.</p>\n<p>There are many tutorials and examples that follow this\nconvention: <code>$</code> or <code>&gt;</code> for commands run as a regular user, and <code>#</code>\nfor commands that should be executed as an administrator.</p>\n<p>Lines that don’t start with <code>$</code> or <code>&gt;</code> character are typically showing\nthe output of the previous command.</p>\n<p>Firstly, make sure to have downloaded and installed Node.js.\nSee <a href=\"https://nodejs.org/en/download/package-manager/\">this guide</a> for further install information.</p>\n<p>Now, create an empty project folder called <code>projects</code>, navigate into it:\nProject folder can be named base on user&#39;s current project title but\nthis example will use <code>projects</code> as the project folder.</p>\n<p>Linux and Mac:</p>\n<pre><code class=\"lang-console\">$ mkdir ~/projects\n$ cd ~/projects\n</code></pre>\n<p>Windows CMD:</p>\n<pre><code class=\"lang-console\">&gt; mkdir %USERPROFILE%\\projects\n&gt; cd %USERPROFILE%\\projects\n</code></pre>\n<p>Windows PowerShell:</p>\n<pre><code class=\"lang-console\">&gt; mkdir $env:USERPROFILE\\projects\n&gt; cd $env:USERPROFILE\\projects\n</code></pre>\n<p>Next, create a new source file in the <code>projects</code>\n folder and call it <code>hello-world.js</code>.</p>\n<p>In Node.js it is considered good style to use\nhyphens (<code>-</code>) or underscores (<code>_</code>) to separate\n multiple words in filenames.</p>\n<p>Open <code>hello-world.js</code> in any preferred text editor and\npaste in the following content.</p>\n<pre><code class=\"lang-js\">const http = require(&#39;http&#39;);\n\nconst hostname = &#39;127.0.0.1&#39;;\nconst port = 3000;\n\nconst server = http.createServer((req, res) =&gt; {\n res.statusCode = 200;\n res.setHeader(&#39;Content-Type&#39;, &#39;text/plain&#39;);\n res.end(&#39;Hello World!\\n&#39;);\n});\n\nserver.listen(port, hostname, () =&gt; {\n console.log(`Server running at http://${hostname}:${port}/`);\n});\n</code></pre>\n<p>Save the file, go back to the terminal window enter the following command:</p>\n<pre><code class=\"lang-console\">$ node hello-world.js\n</code></pre>\n<p>An output like this should appear in the terminal to indicate Node.js\nserver is running:</p>\n<pre><code class=\"lang-console\">Server running at http://127.0.0.1:3000/\n</code></pre>\n<p>Now, open any preferred web browser and visit <code>http://127.0.0.1:3000</code>.</p>\n<p>If the browser displays the string <code>Hello, world!</code>, that indicates\nthe server is working.</p>\n<p>Many of the examples in the documentation can be run similarly.</p>\n"
},
{
"textRaw": "C++ Addons",
"name": "C++ Addons",
"introduced_in": "v0.10.0",
"type": "misc",
"desc": "<p>Node.js Addons are dynamically-linked shared objects, written in C++, that\ncan be loaded into Node.js using the <a href=\"modules.html#modules_require\"><code>require()</code></a> function, and used\njust as if they were an ordinary Node.js module. They are used primarily to\nprovide an interface between JavaScript running in Node.js and C/C++ libraries.</p>\n<p>At the moment, the method for implementing Addons is rather complicated,\ninvolving knowledge of several components and APIs:</p>\n<ul>\n<li><p>V8: the C++ library Node.js currently uses to provide the\nJavaScript implementation. V8 provides the mechanisms for creating objects,\ncalling functions, etc. V8&#39;s API is documented mostly in the\n<code>v8.h</code> header file (<code>deps/v8/include/v8.h</code> in the Node.js source\ntree), which is also available <a href=\"https://v8docs.nodesource.com/\">online</a>.</p>\n</li>\n<li><p><a href=\"https://github.com/libuv/libuv\">libuv</a>: The C library that implements the Node.js event loop, its worker\nthreads and all of the asynchronous behaviors of the platform. It also\nserves as a cross-platform abstraction library, giving easy, POSIX-like\naccess across all major operating systems to many common system tasks, such\nas interacting with the filesystem, sockets, timers, and system events. libuv\nalso provides a pthreads-like threading abstraction that may be used to\npower more sophisticated asynchronous Addons that need to move beyond the\nstandard event loop. Addon authors are encouraged to think about how to\navoid blocking the event loop with I/O or other time-intensive tasks by\noff-loading work via libuv to non-blocking system operations, worker threads\nor a custom use of libuv&#39;s threads.</p>\n</li>\n<li><p>Internal Node.js libraries. Node.js itself exports a number of C++ APIs\nthat Addons can use &mdash; the most important of which is the\n<code>node::ObjectWrap</code> class.</p>\n</li>\n<li><p>Node.js includes a number of other statically linked libraries including\nOpenSSL. These other libraries are located in the <code>deps/</code> directory in the\nNode.js source tree. Only the libuv, OpenSSL, V8 and zlib symbols are\npurposefully re-exported by Node.js and may be used to various extents by\nAddons.\nSee <a href=\"#addons_linking_to_node_js_own_dependencies\">Linking to Node.js&#39; own dependencies</a> for additional information.</p>\n</li>\n</ul>\n<p>All of the following examples are available for <a href=\"https://github.com/nodejs/node-addon-examples\">download</a> and may\nbe used as the starting-point for an Addon.</p>\n",
"miscs": [
{
"textRaw": "Hello world",
"name": "hello_world",
"desc": "<p>This &quot;Hello world&quot; example is a simple Addon, written in C++, that is the\nequivalent of the following JavaScript code:</p>\n<pre><code class=\"lang-js\">module.exports.hello = () =&gt; &#39;world&#39;;\n</code></pre>\n<p>First, create the file <code>hello.cc</code>:</p>\n<pre><code class=\"lang-cpp\">// hello.cc\n#include &lt;node.h&gt;\n\nnamespace demo {\n\nusing v8::FunctionCallbackInfo;\nusing v8::Isolate;\nusing v8::Local;\nusing v8::Object;\nusing v8::String;\nusing v8::Value;\n\nvoid Method(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {\n Isolate* isolate = args.GetIsolate();\n args.GetReturnValue().Set(String::NewFromUtf8(isolate, &quot;world&quot;));\n}\n\nvoid Initialize(Local&lt;Object&gt; exports) {\n NODE_SET_METHOD(exports, &quot;hello&quot;, Method);\n}\n\nNODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)\n\n} // namespace demo\n</code></pre>\n<p>Note that all Node.js Addons must export an initialization function following\nthe pattern:</p>\n<pre><code class=\"lang-cpp\">void Initialize(Local&lt;Object&gt; exports);\nNODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)\n</code></pre>\n<p>There is no semi-colon after <code>NODE_MODULE</code> as it&#39;s not a function (see\n<code>node.h</code>).</p>\n<p>The <code>module_name</code> must match the filename of the final binary (excluding\nthe <code>.node</code> suffix).</p>\n<p>In the <code>hello.cc</code> example, then, the initialization function is <code>Initialize</code>\nand the addon module name is <code>addon</code>.</p>\n",
"modules": [
{
"textRaw": "Building",
"name": "building",
"desc": "<p>Once the source code has been written, it must be compiled into the binary\n<code>addon.node</code> file. To do so, create a file called <code>binding.gyp</code> in the\ntop-level of the project describing the build configuration of the module\nusing a JSON-like format. This file is used by <a href=\"https://github.com/nodejs/node-gyp\">node-gyp</a> — a tool written\nspecifically to compile Node.js Addons.</p>\n<pre><code class=\"lang-json\">{\n &quot;targets&quot;: [\n {\n &quot;target_name&quot;: &quot;addon&quot;,\n &quot;sources&quot;: [ &quot;hello.cc&quot; ]\n }\n ]\n}\n</code></pre>\n<p>A version of the <code>node-gyp</code> utility is bundled and distributed with\nNode.js as part of <code>npm</code>. This version is not made directly available for\ndevelopers to use and is intended only to support the ability to use the\n<code>npm install</code> command to compile and install Addons. Developers who wish to\nuse <code>node-gyp</code> directly can install it using the command\n<code>npm install -g node-gyp</code>. See the <code>node-gyp</code> <a href=\"https://github.com/nodejs/node-gyp#installation\">installation instructions</a> for\nmore information, including platform-specific requirements.</p>\n<p>Once the <code>binding.gyp</code> file has been created, use <code>node-gyp configure</code> to\ngenerate the appropriate project build files for the current platform. This\nwill generate either a <code>Makefile</code> (on Unix platforms) or a <code>vcxproj</code> file\n(on Windows) in the <code>build/</code> directory.</p>\n<p>Next, invoke the <code>node-gyp build</code> command to generate the compiled <code>addon.node</code>\nfile. This will be put into the <code>build/Release/</code> directory.</p>\n<p>When using <code>npm install</code> to install a Node.js Addon, npm uses its own bundled\nversion of <code>node-gyp</code> to perform this same set of actions, generating a\ncompiled version of the Addon for the user&#39;s platform on demand.</p>\n<p>Once built, the binary Addon can be used from within Node.js by pointing\n<a href=\"modules.html#modules_require\"><code>require()</code></a> to the built <code>addon.node</code> module:</p>\n<pre><code class=\"lang-js\">// hello.js\nconst addon = require(&#39;./build/Release/addon&#39;);\n\nconsole.log(addon.hello());\n// Prints: &#39;world&#39;\n</code></pre>\n<p>Please see the examples below for further information or\n<a href=\"https://github.com/arturadib/node-qt\">https://github.com/arturadib/node-qt</a> for an example in production.</p>\n<p>Because the exact path to the compiled Addon binary can vary depending on how\nit is compiled (i.e. sometimes it may be in <code>./build/Debug/</code>), Addons can use\nthe <a href=\"https://github.com/TooTallNate/node-bindings\">bindings</a> package to load the compiled module.</p>\n<p>Note that while the <code>bindings</code> package implementation is more sophisticated\nin how it locates Addon modules, it is essentially using a try-catch pattern\nsimilar to:</p>\n<pre><code class=\"lang-js\">try {\n return require(&#39;./build/Release/addon.node&#39;);\n} catch (err) {\n return require(&#39;./build/Debug/addon.node&#39;);\n}\n</code></pre>\n",
"type": "module",
"displayName": "Building"
},
{
"textRaw": "Linking to Node.js' own dependencies",
"name": "linking_to_node.js'_own_dependencies",
"desc": "<p>Node.js uses a number of statically linked libraries such as V8, libuv and\nOpenSSL. All Addons are required to link to V8 and may link to any of the\nother dependencies as well. Typically, this is as simple as including\nthe appropriate <code>#include &lt;...&gt;</code> statements (e.g. <code>#include &lt;v8.h&gt;</code>) and\n<code>node-gyp</code> will locate the appropriate headers automatically. However, there\nare a few caveats to be aware of:</p>\n<ul>\n<li><p>When <code>node-gyp</code> runs, it will detect the specific release version of Node.js\nand download either the full source tarball or just the headers. If the full\nsource is downloaded, Addons will have complete access to the full set of\nNode.js dependencies. However, if only the Node.js headers are downloaded, then\nonly the symbols exported by Node.js will be available.</p>\n</li>\n<li><p><code>node-gyp</code> can be run using the <code>--nodedir</code> flag pointing at a local Node.js\nsource image. Using this option, the Addon will have access to the full set of\ndependencies.</p>\n</li>\n</ul>\n",
"type": "module",
"displayName": "Linking to Node.js' own dependencies"
},
{
"textRaw": "Loading Addons using require()",
"name": "loading_addons_using_require()",
"desc": "<p>The filename extension of the compiled Addon binary is <code>.node</code> (as opposed\nto <code>.dll</code> or <code>.so</code>). The <a href=\"modules.html#modules_require\"><code>require()</code></a> function is written to look for\nfiles with the <code>.node</code> file extension and initialize those as dynamically-linked\nlibraries.</p>\n<p>When calling <a href=\"modules.html#modules_require\"><code>require()</code></a>, the <code>.node</code> extension can usually be\nomitted and Node.js will still find and initialize the Addon. One caveat,\nhowever, is that Node.js will first attempt to locate and load modules or\nJavaScript files that happen to share the same base name. For instance, if\nthere is a file <code>addon.js</code> in the same directory as the binary <code>addon.node</code>,\nthen <a href=\"modules.html#modules_require\"><code>require(&#39;addon&#39;)</code></a> will give precedence to the <code>addon.js</code> file\nand load it instead.</p>\n",
"type": "module",
"displayName": "Loading Addons using require()"
}
],
"type": "misc",
"displayName": "Hello world"
},
{
"textRaw": "Native Abstractions for Node.js",
"name": "native_abstractions_for_node.js",
"desc": "<p>Each of the examples illustrated in this document make direct use of the\nNode.js and V8 APIs for implementing Addons. It is important to understand\nthat the V8 API can, and has, changed dramatically from one V8 release to the\nnext (and one major Node.js release to the next). With each change, Addons may\nneed to be updated and recompiled in order to continue functioning. The Node.js\nrelease schedule is designed to minimize the frequency and impact of such\nchanges but there is little that Node.js can do currently to ensure stability\nof the V8 APIs.</p>\n<p>The <a href=\"https://github.com/nodejs/nan\">Native Abstractions for Node.js</a> (or <code>nan</code>) provide a set of tools that\nAddon developers are recommended to use to keep compatibility between past and\nfuture releases of V8 and Node.js. See the <code>nan</code> <a href=\"https://github.com/nodejs/nan/tree/master/examples/\">examples</a> for an\nillustration of how it can be used.</p>\n",
"type": "misc",
"displayName": "Native Abstractions for Node.js"
},
{
"textRaw": "N-API",
"name": "n-api",
"stability": 2,
"stabilityText": "Stable",
"desc": "<p>N-API is an API for building native Addons. It is independent from\nthe underlying JavaScript runtime (e.g. V8) and is maintained as part of\nNode.js itself. This API will be Application Binary Interface (ABI) stable\nacross versions of Node.js. It is intended to insulate Addons from\nchanges in the underlying JavaScript engine and allow modules\ncompiled for one version to run on later versions of Node.js without\nrecompilation. Addons are built/packaged with the same approach/tools\noutlined in this document (node-gyp, etc.). The only difference is the\nset of APIs that are used by the native code. Instead of using the V8\nor <a href=\"https://github.com/nodejs/nan\">Native Abstractions for Node.js</a> APIs, the functions available\nin the N-API are used.</p>\n<p>To use N-API in the above &quot;Hello world&quot; example, replace the content of\n<code>hello.cc</code> with the following. All other instructions remain the same.</p>\n<pre><code class=\"lang-cpp\">// hello.cc using N-API\n#include &lt;node_api.h&gt;\n\nnamespace demo {\n\nnapi_value Method(napi_env env, napi_callback_info args) {\n napi_value greeting;\n napi_status status;\n\n status = napi_create_string_utf8(env, &quot;hello&quot;, NAPI_AUTO_LENGTH, &amp;greeting);\n if (status != napi_ok) return nullptr;\n return greeting;\n}\n\nnapi_value init(napi_env env, napi_value exports) {\n napi_status status;\n napi_value fn;\n\n status = napi_create_function(env, nullptr, 0, Method, nullptr, &amp;fn);\n if (status != napi_ok) return nullptr;\n\n status = napi_set_named_property(env, exports, &quot;hello&quot;, fn);\n if (status != napi_ok) return nullptr;\n return exports;\n}\n\nNAPI_MODULE(NODE_GYP_MODULE_NAME, init)\n\n} // namespace demo\n</code></pre>\n<p>The functions available and how to use them are documented in the\nsection titled <a href=\"n-api.html\">C/C++ Addons - N-API</a>.</p>\n",
"type": "misc",
"displayName": "N-API"
},
{
"textRaw": "Addon examples",
"name": "addon_examples",
"desc": "<p>Following are some example Addons intended to help developers get started. The\nexamples make use of the V8 APIs. Refer to the online <a href=\"https://v8docs.nodesource.com/\">V8 reference</a>\nfor help with the various V8 calls, and V8&#39;s <a href=\"https://github.com/v8/v8/wiki/Embedder&#39;s%20Guide\">Embedder&#39;s Guide</a> for an\nexplanation of several concepts used such as handles, scopes, function\ntemplates, etc.</p>\n<p>Each of these examples using the following <code>binding.gyp</code> file:</p>\n<pre><code class=\"lang-json\">{\n &quot;targets&quot;: [\n {\n &quot;target_name&quot;: &quot;addon&quot;,\n &quot;sources&quot;: [ &quot;addon.cc&quot; ]\n }\n ]\n}\n</code></pre>\n<p>In cases where there is more than one <code>.cc</code> file, simply add the additional\nfilename to the <code>sources</code> array:</p>\n<pre><code class=\"lang-json\">&quot;sources&quot;: [&quot;addon.cc&quot;, &quot;myexample.cc&quot;]\n</code></pre>\n<p>Once the <code>binding.gyp</code> file is ready, the example Addons can be configured and\nbuilt using <code>node-gyp</code>:</p>\n<pre><code class=\"lang-console\">$ node-gyp configure build\n</code></pre>\n",
"modules": [
{
"textRaw": "Function arguments",
"name": "function_arguments",
"desc": "<p>Addons will typically expose objects and functions that can be accessed from\nJavaScript running within Node.js. When functions are invoked from JavaScript,\nthe input arguments and return value must be mapped to and from the C/C++\ncode.</p>\n<p>The following example illustrates how to read function arguments passed from\nJavaScript and how to return a result:</p>\n<pre><code class=\"lang-cpp\">// addon.cc\n#include &lt;node.h&gt;\n\nnamespace demo {\n\nusing v8::Exception;\nusing v8::FunctionCallbackInfo;\nusing v8::Isolate;\nusing v8::Local;\nusing v8::Number;\nusing v8::Object;\nusing v8::String;\nusing v8::Value;\n\n// This is the implementation of the &quot;add&quot; method\n// Input arguments are passed using the\n// const FunctionCallbackInfo&lt;Value&gt;&amp; args struct\nvoid Add(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {\n Isolate* isolate = args.GetIsolate();\n\n // Check the number of arguments passed.\n if (args.Length() &lt; 2) {\n // Throw an Error that is passed back to JavaScript\n isolate-&gt;ThrowException(Exception::TypeError(\n String::NewFromUtf8(isolate, &quot;Wrong number of arguments&quot;)));\n return;\n }\n\n // Check the argument types\n if (!args[0]-&gt;IsNumber() || !args[1]-&gt;IsNumber()) {\n isolate-&gt;ThrowException(Exception::TypeError(\n String::NewFromUtf8(isolate, &quot;Wrong arguments&quot;)));\n return;\n }\n\n // Perform the operation\n double value = args[0]-&gt;NumberValue() + args[1]-&gt;NumberValue();\n Local&lt;Number&gt; num = Number::New(isolate, value);\n\n // Set the return value (using the passed in\n // FunctionCallbackInfo&lt;Value&gt;&amp;)\n args.GetReturnValue().Set(num);\n}\n\nvoid Init(Local&lt;Object&gt; exports) {\n NODE_SET_METHOD(exports, &quot;add&quot;, Add);\n}\n\nNODE_MODULE(NODE_GYP_MODULE_NAME, Init)\n\n} // namespace demo\n</code></pre>\n<p>Once compiled, the example Addon can be required and used from within Node.js:</p>\n<pre><code class=\"lang-js\">// test.js\nconst addon = require(&#39;./build/Release/addon&#39;);\n\nconsole.log(&#39;This should be eight:&#39;, addon.add(3, 5));\n</code></pre>\n",
"type": "module",
"displayName": "Function arguments"
},
{
"textRaw": "Callbacks",
"name": "callbacks",
"desc": "<p>It is common practice within Addons to pass JavaScript functions to a C++\nfunction and execute them from there. The following example illustrates how\nto invoke such callbacks:</p>\n<pre><code class=\"lang-cpp\">// addon.cc\n#include &lt;node.h&gt;\n\nnamespace demo {\n\nusing v8::Function;\nusing v8::FunctionCallbackInfo;\nusing v8::Isolate;\nusing v8::Local;\nusing v8::Null;\nusing v8::Object;\nusing v8::String;\nusing v8::Value;\n\nvoid RunCallback(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {\n Isolate* isolate = args.GetIsolate();\n Local&lt;Function&gt; cb = Local&lt;Function&gt;::Cast(args[0]);\n const unsigned argc = 1;\n Local&lt;Value&gt; argv[argc] = { String::NewFromUtf8(isolate, &quot;hello world&quot;) };\n cb-&gt;Call(Null(isolate), argc, argv);\n}\n\nvoid Init(Local&lt;Object&gt; exports, Local&lt;Object&gt; module) {\n NODE_SET_METHOD(module, &quot;exports&quot;, RunCallback);\n}\n\nNODE_MODULE(NODE_GYP_MODULE_NAME, Init)\n\n} // namespace demo\n</code></pre>\n<p>Note that this example uses a two-argument form of <code>Init()</code> that receives\nthe full <code>module</code> object as the second argument. This allows the Addon\nto completely overwrite <code>exports</code> with a single function instead of\nadding the function as a property of <code>exports</code>.</p>\n<p>To test it, run the following JavaScript:</p>\n<pre><code class=\"lang-js\">// test.js\nconst addon = require(&#39;./build/Release/addon&#39;);\n\naddon((msg) =&gt; {\n console.log(msg);\n// Prints: &#39;hello world&#39;\n});\n</code></pre>\n<p>Note that, in this example, the callback function is invoked synchronously.</p>\n",
"type": "module",
"displayName": "Callbacks"
},
{
"textRaw": "Object factory",
"name": "object_factory",
"desc": "<p>Addons can create and return new objects from within a C++ function as\nillustrated in the following example. An object is created and returned with a\nproperty <code>msg</code> that echoes the string passed to <code>createObject()</code>:</p>\n<pre><code class=\"lang-cpp\">// addon.cc\n#include &lt;node.h&gt;\n\nnamespace demo {\n\nusing v8::FunctionCallbackInfo;\nusing v8::Isolate;\nusing v8::Local;\nusing v8::Object;\nusing v8::String;\nusing v8::Value;\n\nvoid CreateObject(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {\n Isolate* isolate = args.GetIsolate();\n\n Local&lt;Object&gt; obj = Object::New(isolate);\n obj-&gt;Set(String::NewFromUtf8(isolate, &quot;msg&quot;), args[0]-&gt;ToString());\n\n args.GetReturnValue().Set(obj);\n}\n\nvoid Init(Local&lt;Object&gt; exports, Local&lt;Object&gt; module) {\n NODE_SET_METHOD(module, &quot;exports&quot;, CreateObject);\n}\n\nNODE_MODULE(NODE_GYP_MODULE_NAME, Init)\n\n} // namespace demo\n</code></pre>\n<p>To test it in JavaScript:</p>\n<pre><code class=\"lang-js\">// test.js\nconst addon = require(&#39;./build/Release/addon&#39;);\n\nconst obj1 = addon(&#39;hello&#39;);\nconst obj2 = addon(&#39;world&#39;);\nconsole.log(obj1.msg, obj2.msg);\n// Prints: &#39;hello world&#39;\n</code></pre>\n",
"type": "module",
"displayName": "Object factory"
},
{
"textRaw": "Function factory",
"name": "function_factory",
"desc": "<p>Another common scenario is creating JavaScript functions that wrap C++\nfunctions and returning those back to JavaScript:</p>\n<pre><code class=\"lang-cpp\">// addon.cc\n#include &lt;node.h&gt;\n\nnamespace demo {\n\nusing v8::Function;\nusing v8::FunctionCallbackInfo;\nusing v8::FunctionTemplate;\nusing v8::Isolate;\nusing v8::Local;\nusing v8::Object;\nusing v8::String;\nusing v8::Value;\n\nvoid MyFunction(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {\n Isolate* isolate = args.GetIsolate();\n args.GetReturnValue().Set(String::NewFromUtf8(isolate, &quot;hello world&quot;));\n}\n\nvoid CreateFunction(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {\n Isolate* isolate = args.GetIsolate();\n\n Local&lt;FunctionTemplate&gt; tpl = FunctionTemplate::New(isolate, MyFunction);\n Local&lt;Function&gt; fn = tpl-&gt;GetFunction();\n\n // omit this to make it anonymous\n fn-&gt;SetName(String::NewFromUtf8(isolate, &quot;theFunction&quot;));\n\n args.GetReturnValue().Set(fn);\n}\n\nvoid Init(Local&lt;Object&gt; exports, Local&lt;Object&gt; module) {\n NODE_SET_METHOD(module, &quot;exports&quot;, CreateFunction);\n}\n\nNODE_MODULE(NODE_GYP_MODULE_NAME, Init)\n\n} // namespace demo\n</code></pre>\n<p>To test:</p>\n<pre><code class=\"lang-js\">// test.js\nconst addon = require(&#39;./build/Release/addon&#39;);\n\nconst fn = addon();\nconsole.log(fn());\n// Prints: &#39;hello world&#39;\n</code></pre>\n",
"type": "module",
"displayName": "Function factory"
},
{
"textRaw": "Wrapping C++ objects",
"name": "wrapping_c++_objects",
"desc": "<p>It is also possible to wrap C++ objects/classes in a way that allows new\ninstances to be created using the JavaScript <code>new</code> operator:</p>\n<pre><code class=\"lang-cpp\">// addon.cc\n#include &lt;node.h&gt;\n#include &quot;myobject.h&quot;\n\nnamespace demo {\n\nusing v8::Local;\nusing v8::Object;\n\nvoid InitAll(Local&lt;Object&gt; exports) {\n MyObject::Init(exports);\n}\n\nNODE_MODULE(NODE_GYP_MODULE_NAME, InitAll)\n\n} // namespace demo\n</code></pre>\n<p>Then, in <code>myobject.h</code>, the wrapper class inherits from <code>node::ObjectWrap</code>:</p>\n<pre><code class=\"lang-cpp\">// myobject.h\n#ifndef MYOBJECT_H\n#define MYOBJECT_H\n\n#include &lt;node.h&gt;\n#include &lt;node_object_wrap.h&gt;\n\nnamespace demo {\n\nclass MyObject : public node::ObjectWrap {\n public:\n static void Init(v8::Local&lt;v8::Object&gt; exports);\n\n private:\n explicit MyObject(double value = 0);\n ~MyObject();\n\n static void New(const v8::FunctionCallbackInfo&lt;v8::Value&gt;&amp; args);\n static void PlusOne(const v8::FunctionCallbackInfo&lt;v8::Value&gt;&amp; args);\n static v8::Persistent&lt;v8::Function&gt; constructor;\n double value_;\n};\n\n} // namespace demo\n\n#endif\n</code></pre>\n<p>In <code>myobject.cc</code>, implement the various methods that are to be exposed.\nBelow, the method <code>plusOne()</code> is exposed by adding it to the constructor&#39;s\nprototype:</p>\n<pre><code class=\"lang-cpp\">// myobject.cc\n#include &quot;myobject.h&quot;\n\nnamespace demo {\n\nusing v8::Context;\nusing v8::Function;\nusing v8::FunctionCallbackInfo;\nusing v8::FunctionTemplate;\nusing v8::Isolate;\nusing v8::Local;\nusing v8::Number;\nusing v8::Object;\nusing v8::Persistent;\nusing v8::String;\nusing v8::Value;\n\nPersistent&lt;Function&gt; MyObject::constructor;\n\nMyObject::MyObject(double value) : value_(value) {\n}\n\nMyObject::~MyObject() {\n}\n\nvoid MyObject::Init(Local&lt;Object&gt; exports) {\n Isolate* isolate = exports-&gt;GetIsolate();\n\n // Prepare constructor template\n Local&lt;FunctionTemplate&gt; tpl = FunctionTemplate::New(isolate, New);\n tpl-&gt;SetClassName(String::NewFromUtf8(isolate, &quot;MyObject&quot;));\n tpl-&gt;InstanceTemplate()-&gt;SetInternalFieldCount(1);\n\n // Prototype\n NODE_SET_PROTOTYPE_METHOD(tpl, &quot;plusOne&quot;, PlusOne);\n\n constructor.Reset(isolate, tpl-&gt;GetFunction());\n exports-&gt;Set(String::NewFromUtf8(isolate, &quot;MyObject&quot;),\n tpl-&gt;GetFunction());\n}\n\nvoid MyObject::New(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {\n Isolate* isolate = args.GetIsolate();\n\n if (args.IsConstructCall()) {\n // Invoked as constructor: `new MyObject(...)`\n double value = args[0]-&gt;IsUndefined() ? 0 : args[0]-&gt;NumberValue();\n MyObject* obj = new MyObject(value);\n obj-&gt;Wrap(args.This());\n args.GetReturnValue().Set(args.This());\n } else {\n // Invoked as plain function `MyObject(...)`, turn into construct call.\n const int argc = 1;\n Local&lt;Value&gt; argv[argc] = { args[0] };\n Local&lt;Context&gt; context = isolate-&gt;GetCurrentContext();\n Local&lt;Function&gt; cons = Local&lt;Function&gt;::New(isolate, constructor);\n Local&lt;Object&gt; result =\n cons-&gt;NewInstance(context, argc, argv).ToLocalChecked();\n args.GetReturnValue().Set(result);\n }\n}\n\nvoid MyObject::PlusOne(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {\n Isolate* isolate = args.GetIsolate();\n\n MyObject* obj = ObjectWrap::Unwrap&lt;MyObject&gt;(args.Holder());\n obj-&gt;value_ += 1;\n\n args.GetReturnValue().Set(Number::New(isolate, obj-&gt;value_));\n}\n\n} // namespace demo\n</code></pre>\n<p>To build this example, the <code>myobject.cc</code> file must be added to the\n<code>binding.gyp</code>:</p>\n<pre><code class=\"lang-json\">{\n &quot;targets&quot;: [\n {\n &quot;target_name&quot;: &quot;addon&quot;,\n &quot;sources&quot;: [\n &quot;addon.cc&quot;,\n &quot;myobject.cc&quot;\n ]\n }\n ]\n}\n</code></pre>\n<p>Test it with:</p>\n<pre><code class=\"lang-js\">// test.js\nconst addon = require(&#39;./build/Release/addon&#39;);\n\nconst obj = new addon.MyObject(10);\nconsole.log(obj.plusOne());\n// Prints: 11\nconsole.log(obj.plusOne());\n// Prints: 12\nconsole.log(obj.plusOne());\n// Prints: 13\n</code></pre>\n",
"type": "module",
"displayName": "Wrapping C++ objects"
},
{
"textRaw": "Factory of wrapped objects",
"name": "factory_of_wrapped_objects",
"desc": "<p>Alternatively, it is possible to use a factory pattern to avoid explicitly\ncreating object instances using the JavaScript <code>new</code> operator:</p>\n<pre><code class=\"lang-js\">const obj = addon.createObject();\n// instead of:\n// const obj = new addon.Object();\n</code></pre>\n<p>First, the <code>createObject()</code> method is implemented in <code>addon.cc</code>:</p>\n<pre><code class=\"lang-cpp\">// addon.cc\n#include &lt;node.h&gt;\n#include &quot;myobject.h&quot;\n\nnamespace demo {\n\nusing v8::FunctionCallbackInfo;\nusing v8::Isolate;\nusing v8::Local;\nusing v8::Object;\nusing v8::String;\nusing v8::Value;\n\nvoid CreateObject(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {\n MyObject::NewInstance(args);\n}\n\nvoid InitAll(Local&lt;Object&gt; exports, Local&lt;Object&gt; module) {\n MyObject::Init(exports-&gt;GetIsolate());\n\n NODE_SET_METHOD(module, &quot;exports&quot;, CreateObject);\n}\n\nNODE_MODULE(NODE_GYP_MODULE_NAME, InitAll)\n\n} // namespace demo\n</code></pre>\n<p>In <code>myobject.h</code>, the static method <code>NewInstance()</code> is added to handle\ninstantiating the object. This method takes the place of using <code>new</code> in\nJavaScript:</p>\n<pre><code class=\"lang-cpp\">// myobject.h\n#ifndef MYOBJECT_H\n#define MYOBJECT_H\n\n#include &lt;node.h&gt;\n#include &lt;node_object_wrap.h&gt;\n\nnamespace demo {\n\nclass MyObject : public node::ObjectWrap {\n public:\n static void Init(v8::Isolate* isolate);\n static void NewInstance(const v8::FunctionCallbackInfo&lt;v8::Value&gt;&amp; args);\n\n private:\n explicit MyObject(double value = 0);\n ~MyObject();\n\n static void New(const v8::FunctionCallbackInfo&lt;v8::Value&gt;&amp; args);\n static void PlusOne(const v8::FunctionCallbackInfo&lt;v8::Value&gt;&amp; args);\n static v8::Persistent&lt;v8::Function&gt; constructor;\n double value_;\n};\n\n} // namespace demo\n\n#endif\n</code></pre>\n<p>The implementation in <code>myobject.cc</code> is similar to the previous example:</p>\n<pre><code class=\"lang-cpp\">// myobject.cc\n#include &lt;node.h&gt;\n#include &quot;myobject.h&quot;\n\nnamespace demo {\n\nusing v8::Context;\nusing v8::Function;\nusing v8::FunctionCallbackInfo;\nusing v8::FunctionTemplate;\nusing v8::Isolate;\nusing v8::Local;\nusing v8::Number;\nusing v8::Object;\nusing v8::Persistent;\nusing v8::String;\nusing v8::Value;\n\nPersistent&lt;Function&gt; MyObject::constructor;\n\nMyObject::MyObject(double value) : value_(value) {\n}\n\nMyObject::~MyObject() {\n}\n\nvoid MyObject::Init(Isolate* isolate) {\n // Prepare constructor template\n Local&lt;FunctionTemplate&gt; tpl = FunctionTemplate::New(isolate, New);\n tpl-&gt;SetClassName(String::NewFromUtf8(isolate, &quot;MyObject&quot;));\n tpl-&gt;InstanceTemplate()-&gt;SetInternalFieldCount(1);\n\n // Prototype\n NODE_SET_PROTOTYPE_METHOD(tpl, &quot;plusOne&quot;, PlusOne);\n\n constructor.Reset(isolate, tpl-&gt;GetFunction());\n}\n\nvoid MyObject::New(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {\n Isolate* isolate = args.GetIsolate();\n\n if (args.IsConstructCall()) {\n // Invoked as constructor: `new MyObject(...)`\n double value = args[0]-&gt;IsUndefined() ? 0 : args[0]-&gt;NumberValue();\n MyObject* obj = new MyObject(value);\n obj-&gt;Wrap(args.This());\n args.GetReturnValue().Set(args.This());\n } else {\n // Invoked as plain function `MyObject(...)`, turn into construct call.\n const int argc = 1;\n Local&lt;Value&gt; argv[argc] = { args[0] };\n Local&lt;Function&gt; cons = Local&lt;Function&gt;::New(isolate, constructor);\n Local&lt;Context&gt; context = isolate-&gt;GetCurrentContext();\n Local&lt;Object&gt; instance =\n cons-&gt;NewInstance(context, argc, argv).ToLocalChecked();\n args.GetReturnValue().Set(instance);\n }\n}\n\nvoid MyObject::NewInstance(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {\n Isolate* isolate = args.GetIsolate();\n\n const unsigned argc = 1;\n Local&lt;Value&gt; argv[argc] = { args[0] };\n Local&lt;Function&gt; cons = Local&lt;Function&gt;::New(isolate, constructor);\n Local&lt;Context&gt; context = isolate-&gt;GetCurrentContext();\n Local&lt;Object&gt; instance =\n cons-&gt;NewInstance(context, argc, argv).ToLocalChecked();\n\n args.GetReturnValue().Set(instance);\n}\n\nvoid MyObject::PlusOne(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {\n Isolate* isolate = args.GetIsolate();\n\n MyObject* obj = ObjectWrap::Unwrap&lt;MyObject&gt;(args.Holder());\n obj-&gt;value_ += 1;\n\n args.GetReturnValue().Set(Number::New(isolate, obj-&gt;value_));\n}\n\n} // namespace demo\n</code></pre>\n<p>Once again, to build this example, the <code>myobject.cc</code> file must be added to the\n<code>binding.gyp</code>:</p>\n<pre><code class=\"lang-json\">{\n &quot;targets&quot;: [\n {\n &quot;target_name&quot;: &quot;addon&quot;,\n &quot;sources&quot;: [\n &quot;addon.cc&quot;,\n &quot;myobject.cc&quot;\n ]\n }\n ]\n}\n</code></pre>\n<p>Test it with:</p>\n<pre><code class=\"lang-js\">// test.js\nconst createObject = require(&#39;./build/Release/addon&#39;);\n\nconst obj = createObject(10);\nconsole.log(obj.plusOne());\n// Prints: 11\nconsole.log(obj.plusOne());\n// Prints: 12\nconsole.log(obj.plusOne());\n// Prints: 13\n\nconst obj2 = createObject(20);\nconsole.log(obj2.plusOne());\n// Prints: 21\nconsole.log(obj2.plusOne());\n// Prints: 22\nconsole.log(obj2.plusOne());\n// Prints: 23\n</code></pre>\n",
"type": "module",
"displayName": "Factory of wrapped objects"
},
{
"textRaw": "Passing wrapped objects around",
"name": "passing_wrapped_objects_around",
"desc": "<p>In addition to wrapping and returning C++ objects, it is possible to pass\nwrapped objects around by unwrapping them with the Node.js helper function\n<code>node::ObjectWrap::Unwrap</code>. The following examples shows a function <code>add()</code>\nthat can take two <code>MyObject</code> objects as input arguments:</p>\n<pre><code class=\"lang-cpp\">// addon.cc\n#include &lt;node.h&gt;\n#include &lt;node_object_wrap.h&gt;\n#include &quot;myobject.h&quot;\n\nnamespace demo {\n\nusing v8::FunctionCallbackInfo;\nusing v8::Isolate;\nusing v8::Local;\nusing v8::Number;\nusing v8::Object;\nusing v8::String;\nusing v8::Value;\n\nvoid CreateObject(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {\n MyObject::NewInstance(args);\n}\n\nvoid Add(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {\n Isolate* isolate = args.GetIsolate();\n\n MyObject* obj1 = node::ObjectWrap::Unwrap&lt;MyObject&gt;(\n args[0]-&gt;ToObject());\n MyObject* obj2 = node::ObjectWrap::Unwrap&lt;MyObject&gt;(\n args[1]-&gt;ToObject());\n\n double sum = obj1-&gt;value() + obj2-&gt;value();\n args.GetReturnValue().Set(Number::New(isolate, sum));\n}\n\nvoid InitAll(Local&lt;Object&gt; exports) {\n MyObject::Init(exports-&gt;GetIsolate());\n\n NODE_SET_METHOD(exports, &quot;createObject&quot;, CreateObject);\n NODE_SET_METHOD(exports, &quot;add&quot;, Add);\n}\n\nNODE_MODULE(NODE_GYP_MODULE_NAME, InitAll)\n\n} // namespace demo\n</code></pre>\n<p>In <code>myobject.h</code>, a new public method is added to allow access to private values\nafter unwrapping the object.</p>\n<pre><code class=\"lang-cpp\">// myobject.h\n#ifndef MYOBJECT_H\n#define MYOBJECT_H\n\n#include &lt;node.h&gt;\n#include &lt;node_object_wrap.h&gt;\n\nnamespace demo {\n\nclass MyObject : public node::ObjectWrap {\n public:\n static void Init(v8::Isolate* isolate);\n static void NewInstance(const v8::FunctionCallbackInfo&lt;v8::Value&gt;&amp; args);\n inline double value() const { return value_; }\n\n private:\n explicit MyObject(double value = 0);\n ~MyObject();\n\n static void New(const v8::FunctionCallbackInfo&lt;v8::Value&gt;&amp; args);\n static v8::Persistent&lt;v8::Function&gt; constructor;\n double value_;\n};\n\n} // namespace demo\n\n#endif\n</code></pre>\n<p>The implementation of <code>myobject.cc</code> is similar to before:</p>\n<pre><code class=\"lang-cpp\">// myobject.cc\n#include &lt;node.h&gt;\n#include &quot;myobject.h&quot;\n\nnamespace demo {\n\nusing v8::Context;\nusing v8::Function;\nusing v8::FunctionCallbackInfo;\nusing v8::FunctionTemplate;\nusing v8::Isolate;\nusing v8::Local;\nusing v8::Object;\nusing v8::Persistent;\nusing v8::String;\nusing v8::Value;\n\nPersistent&lt;Function&gt; MyObject::constructor;\n\nMyObject::MyObject(double value) : value_(value) {\n}\n\nMyObject::~MyObject() {\n}\n\nvoid MyObject::Init(Isolate* isolate) {\n // Prepare constructor template\n Local&lt;FunctionTemplate&gt; tpl = FunctionTemplate::New(isolate, New);\n tpl-&gt;SetClassName(String::NewFromUtf8(isolate, &quot;MyObject&quot;));\n tpl-&gt;InstanceTemplate()-&gt;SetInternalFieldCount(1);\n\n constructor.Reset(isolate, tpl-&gt;GetFunction());\n}\n\nvoid MyObject::New(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {\n Isolate* isolate = args.GetIsolate();\n\n if (args.IsConstructCall()) {\n // Invoked as constructor: `new MyObject(...)`\n double value = args[0]-&gt;IsUndefined() ? 0 : args[0]-&gt;NumberValue();\n MyObject* obj = new MyObject(value);\n obj-&gt;Wrap(args.This());\n args.GetReturnValue().Set(args.This());\n } else {\n // Invoked as plain function `MyObject(...)`, turn into construct call.\n const int argc = 1;\n Local&lt;Value&gt; argv[argc] = { args[0] };\n Local&lt;Context&gt; context = isolate-&gt;GetCurrentContext();\n Local&lt;Function&gt; cons = Local&lt;Function&gt;::New(isolate, constructor);\n Local&lt;Object&gt; instance =\n cons-&gt;NewInstance(context, argc, argv).ToLocalChecked();\n args.GetReturnValue().Set(instance);\n }\n}\n\nvoid MyObject::NewInstance(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {\n Isolate* isolate = args.GetIsolate();\n\n const unsigned argc = 1;\n Local&lt;Value&gt; argv[argc] = { args[0] };\n Local&lt;Function&gt; cons = Local&lt;Function&gt;::New(isolate, constructor);\n Local&lt;Context&gt; context = isolate-&gt;GetCurrentContext();\n Local&lt;Object&gt; instance =\n cons-&gt;NewInstance(context, argc, argv).ToLocalChecked();\n\n args.GetReturnValue().Set(instance);\n}\n\n} // namespace demo\n</code></pre>\n<p>Test it with:</p>\n<pre><code class=\"lang-js\">// test.js\nconst addon = require(&#39;./build/Release/addon&#39;);\n\nconst obj1 = addon.createObject(10);\nconst obj2 = addon.createObject(20);\nconst result = addon.add(obj1, obj2);\n\nconsole.log(result);\n// Prints: 30\n</code></pre>\n",
"type": "module",
"displayName": "Passing wrapped objects around"
},
{
"textRaw": "AtExit hooks",
"name": "atexit_hooks",
"desc": "<p>An <code>AtExit</code> hook is a function that is invoked after the Node.js event loop\nhas ended but before the JavaScript VM is terminated and Node.js shuts down.\n<code>AtExit</code> hooks are registered using the <code>node::AtExit</code> API.</p>\n",
"modules": [
{
"textRaw": "void AtExit(callback, args)",
"name": "void_atexit(callback,_args)",
"desc": "<ul>\n<li><code>callback</code> <span class=\"type\">&lt;void (*)(void*)&gt;</span>\nA pointer to the function to call at exit.</li>\n<li><code>args</code> <span class=\"type\">&lt;void*&gt;</span>\nA pointer to pass to the callback at exit.</li>\n</ul>\n<p>Registers exit hooks that run after the event loop has ended but before the VM\nis killed.</p>\n<p><code>AtExit</code> takes two parameters: a pointer to a callback function to run at exit,\nand a pointer to untyped context data to be passed to that callback.</p>\n<p>Callbacks are run in last-in first-out order.</p>\n<p>The following <code>addon.cc</code> implements <code>AtExit</code>:</p>\n<pre><code class=\"lang-cpp\">// addon.cc\n#include &lt;assert.h&gt;\n#include &lt;stdlib.h&gt;\n#include &lt;node.h&gt;\n\nnamespace demo {\n\nusing node::AtExit;\nusing v8::HandleScope;\nusing v8::Isolate;\nusing v8::Local;\nusing v8::Object;\n\nstatic char cookie[] = &quot;yum yum&quot;;\nstatic int at_exit_cb1_called = 0;\nstatic int at_exit_cb2_called = 0;\n\nstatic void at_exit_cb1(void* arg) {\n Isolate* isolate = static_cast&lt;Isolate*&gt;(arg);\n HandleScope scope(isolate);\n Local&lt;Object&gt; obj = Object::New(isolate);\n assert(!obj.IsEmpty()); // assert VM is still alive\n assert(obj-&gt;IsObject());\n at_exit_cb1_called++;\n}\n\nstatic void at_exit_cb2(void* arg) {\n assert(arg == static_cast&lt;void*&gt;(cookie));\n at_exit_cb2_called++;\n}\n\nstatic void sanity_check(void*) {\n assert(at_exit_cb1_called == 1);\n assert(at_exit_cb2_called == 2);\n}\n\nvoid init(Local&lt;Object&gt; exports) {\n AtExit(at_exit_cb2, cookie);\n AtExit(at_exit_cb2, cookie);\n AtExit(at_exit_cb1, exports-&gt;GetIsolate());\n AtExit(sanity_check);\n}\n\nNODE_MODULE(NODE_GYP_MODULE_NAME, init)\n\n} // namespace demo\n</code></pre>\n<p>Test in JavaScript by running:</p>\n<pre><code class=\"lang-js\">// test.js\nrequire(&#39;./build/Release/addon&#39;);\n</code></pre>\n",
"type": "module",
"displayName": "void AtExit(callback, args)"
}
],
"type": "module",
"displayName": "AtExit hooks"
}
],
"type": "misc",
"displayName": "Addon examples"
}
]
},
{
"textRaw": "N-API",
"name": "N-API",
"introduced_in": "v7.10.0",
"type": "misc",
"stability": 2,
"stabilityText": "Stable",
"desc": "<p>N-API (pronounced N as in the letter, followed by API)\nis an API for building native Addons. It is independent from\nthe underlying JavaScript runtime (ex V8) and is maintained as part of\nNode.js itself. This API will be Application Binary Interface (ABI) stable\nacross versions of Node.js. It is intended to insulate Addons from\nchanges in the underlying JavaScript engine and allow modules\ncompiled for one version to run on later versions of Node.js without\nrecompilation.</p>\n<p>Addons are built/packaged with the same approach/tools\noutlined in the section titled <a href=\"addons.html\">C++ Addons</a>.\nThe only difference is the set of APIs that are used by the native code.\nInstead of using the V8 or <a href=\"https://github.com/nodejs/nan\">Native Abstractions for Node.js</a> APIs,\nthe functions available in the N-API are used.</p>\n<p>APIs exposed by N-API are generally used to create and manipulate\nJavaScript values. Concepts and operations generally map to ideas specified\nin the ECMA262 Language Specification. The APIs have the following\nproperties:</p>\n<ul>\n<li>All N-API calls return a status code of type <code>napi_status</code>. This\nstatus indicates whether the API call succeeded or failed.</li>\n<li>The API&#39;s return value is passed via an out parameter.</li>\n<li>All JavaScript values are abstracted behind an opaque type named\n<code>napi_value</code>.</li>\n<li>In case of an error status code, additional information can be obtained\nusing <code>napi_get_last_error_info</code>. More information can be found in the error\nhandling section <a href=\"#n_api_error_handling\">Error Handling</a>.</li>\n</ul>\n<p>The N-API is a C API that ensures ABI stability across Node.js versions\nand different compiler levels. However, we also understand that a C++\nAPI can be easier to use in many cases. To support these cases we expect\nthere to be one or more C++ wrapper modules that provide an inlineable C++\nAPI. Binaries built with these wrapper modules will depend on the symbols\nfor the N-API C based functions exported by Node.js. These wrappers are not\npart of N-API, nor will they be maintained as part of Node.js. One such\nexample is: <a href=\"https://github.com/nodejs/node-addon-api\">node-addon-api</a>.</p>\n<p>In order to use the N-API functions, include the file\n<a href=\"https://github.com/nodejs/node/blob/master/src/node_api.h\"><code>node_api.h</code></a>\nwhich is located in the src directory in the node development tree:</p>\n<pre><code class=\"lang-C\">#include &lt;node_api.h&gt;\n</code></pre>\n",
"miscs": [
{
"textRaw": "Basic N-API Data Types",
"name": "basic_n-api_data_types",
"desc": "<p>N-API exposes the following fundamental datatypes as abstractions that are\nconsumed by the various APIs. These APIs should be treated as opaque,\nintrospectable only with other N-API calls.</p>\n",
"modules": [
{
"textRaw": "napi_status",
"name": "napi_status",
"desc": "<p>Integral status code indicating the success or failure of a N-API call.\nCurrently, the following status codes are supported.</p>\n<pre><code class=\"lang-C\">typedef enum {\n napi_ok,\n napi_invalid_arg,\n napi_object_expected,\n napi_string_expected,\n napi_name_expected,\n napi_function_expected,\n napi_number_expected,\n napi_boolean_expected,\n napi_array_expected,\n napi_generic_failure,\n napi_pending_exception,\n napi_cancelled,\n napi_escape_called_twice,\n napi_handle_scope_mismatch,\n napi_callback_scope_mismatch,\n#ifdef NAPI_EXPERIMENTAL\n napi_queue_full,\n napi_closing,\n#endif // NAPI_EXPERIMENTAL\n} napi_status;\n</code></pre>\n<p>If additional information is required upon an API returning a failed status,\nit can be obtained by calling <code>napi_get_last_error_info</code>.</p>\n",
"type": "module",
"displayName": "napi_status"
},
{
"textRaw": "napi_extended_error_info",
"name": "napi_extended_error_info",
"desc": "<pre><code class=\"lang-C\">typedef struct {\n const char* error_message;\n void* engine_reserved;\n uint32_t engine_error_code;\n napi_status error_code;\n} napi_extended_error_info;\n</code></pre>\n<ul>\n<li><code>error_message</code>: UTF8-encoded string containing a VM-neutral description of\nthe error.</li>\n<li><code>engine_reserved</code>: Reserved for VM-specific error details. This is currently\nnot implemented for any VM.</li>\n<li><code>engine_error_code</code>: VM-specific error code. This is currently\nnot implemented for any VM.</li>\n<li><code>error_code</code>: The N-API status code that originated with the last error.</li>\n</ul>\n<p>See the <a href=\"#n_api_error_handling\">Error Handling</a> section for additional information.</p>\n",
"type": "module",
"displayName": "napi_extended_error_info"
},
{
"textRaw": "napi_env",
"name": "napi_env",
"desc": "<p><code>napi_env</code> is used to represent a context that the underlying N-API\nimplementation can use to persist VM-specific state. This structure is passed\nto native functions when they&#39;re invoked, and it must be passed back when\nmaking N-API calls. Specifically, the same <code>napi_env</code> that was passed in when\nthe initial native function was called must be passed to any subsequent\nnested N-API calls. Caching the <code>napi_env</code> for the purpose of general reuse is\nnot allowed.</p>\n",
"type": "module",
"displayName": "napi_env"
},
{
"textRaw": "napi_value",
"name": "napi_value",
"desc": "<p>This is an opaque pointer that is used to represent a JavaScript value.</p>\n",
"type": "module",
"displayName": "napi_value"
},
{
"textRaw": "napi_threadsafe_function",
"name": "napi_threadsafe_function",
"stability": 1,
"stabilityText": "Experimental",
"desc": "<p>This is an opaque pointer that represents a JavaScript function which can be\ncalled asynchronously from multiple threads via\n<code>napi_call_threadsafe_function()</code>.</p>\n",
"type": "module",
"displayName": "napi_threadsafe_function"
},
{
"textRaw": "napi_threadsafe_function_release_mode",
"name": "napi_threadsafe_function_release_mode",
"stability": 1,
"stabilityText": "Experimental",
"desc": "<p>A value to be given to <code>napi_release_threadsafe_function()</code> to indicate whether\nthe thread-safe function is to be closed immediately (<code>napi_tsfn_abort</code>) or\nmerely released (<code>napi_tsfn_release</code>) and thus available for subsequent use via\n<code>napi_acquire_threadsafe_function()</code> and <code>napi_call_threadsafe_function()</code>.</p>\n<pre><code class=\"lang-C\">typedef enum {\n napi_tsfn_release,\n napi_tsfn_abort\n} napi_threadsafe_function_release_mode;\n</code></pre>\n",
"type": "module",
"displayName": "napi_threadsafe_function_release_mode"
},
{
"textRaw": "napi_threadsafe_function_call_mode",
"name": "napi_threadsafe_function_call_mode",
"stability": 1,
"stabilityText": "Experimental",
"desc": "<p>A value to be given to <code>napi_call_threadsafe_function()</code> to indicate whether\nthe call should block whenever the queue associated with the thread-safe\nfunction is full.</p>\n<pre><code class=\"lang-C\">typedef enum {\n napi_tsfn_nonblocking,\n napi_tsfn_blocking\n} napi_threadsafe_function_call_mode;\n</code></pre>\n",
"type": "module",
"displayName": "napi_threadsafe_function_call_mode"
},
{
"textRaw": "N-API Memory Management types",
"name": "n-api_memory_management_types",
"modules": [
{
"textRaw": "napi_handle_scope",
"name": "napi_handle_scope",
"desc": "<p>This is an abstraction used to control and modify the lifetime of objects\ncreated within a particular scope. In general, N-API values are created within\nthe context of a handle scope. When a native method is called from\nJavaScript, a default handle scope will exist. If the user does not explicitly\ncreate a new handle scope, N-API values will be created in the default handle\nscope. For any invocations of code outside the execution of a native method\n(for instance, during a libuv callback invocation), the module is required to\ncreate a scope before invoking any functions that can result in the creation\nof JavaScript values.</p>\n<p>Handle scopes are created using <a href=\"#n_api_napi_open_handle_scope\"><code>napi_open_handle_scope</code></a> and are destroyed\nusing <a href=\"#n_api_napi_close_handle_scope\"><code>napi_close_handle_scope</code></a>. Closing the scope can indicate to the GC\nthat all <code>napi_value</code>s created during the lifetime of the handle scope are no\nlonger referenced from the current stack frame.</p>\n<p>For more details, review the <a href=\"#n_api_object_lifetime_management\">Object Lifetime Management</a>.</p>\n",
"type": "module",
"displayName": "napi_handle_scope"
},
{
"textRaw": "napi_escapable_handle_scope",
"name": "napi_escapable_handle_scope",
"desc": "<p>Escapable handle scopes are a special type of handle scope to return values\ncreated within a particular handle scope to a parent scope.</p>\n",
"type": "module",
"displayName": "napi_escapable_handle_scope"
},
{
"textRaw": "napi_ref",
"name": "napi_ref",
"desc": "<p>This is the abstraction to use to reference a <code>napi_value</code>. This allows for\nusers to manage the lifetimes of JavaScript values, including defining their\nminimum lifetimes explicitly.</p>\n<p>For more details, review the <a href=\"#n_api_object_lifetime_management\">Object Lifetime Management</a>.</p>\n",
"type": "module",
"displayName": "napi_ref"
}
],
"type": "module",
"displayName": "N-API Memory Management types"
},
{
"textRaw": "N-API Callback types",
"name": "n-api_callback_types",
"modules": [
{
"textRaw": "napi_callback_info",
"name": "napi_callback_info",
"desc": "<p>Opaque datatype that is passed to a callback function. It can be used for\ngetting additional information about the context in which the callback was\ninvoked.</p>\n",
"type": "module",
"displayName": "napi_callback_info"
},
{
"textRaw": "napi_callback",
"name": "napi_callback",
"desc": "<p>Function pointer type for user-provided native functions which are to be\nexposed to JavaScript via N-API. Callback functions should satisfy the\nfollowing signature:</p>\n<pre><code class=\"lang-C\">typedef napi_value (*napi_callback)(napi_env, napi_callback_info);\n</code></pre>\n",
"type": "module",
"displayName": "napi_callback"
},
{
"textRaw": "napi_finalize",
"name": "napi_finalize",
"desc": "<p>Function pointer type for add-on provided functions that allow the user to be\nnotified when externally-owned data is ready to be cleaned up because the\nobject with which it was associated with, has been garbage-collected. The user\nmust provide a function satisfying the following signature which would get\ncalled upon the object&#39;s collection. Currently, <code>napi_finalize</code> can be used for\nfinding out when objects that have external data are collected.</p>\n<pre><code class=\"lang-C\">typedef void (*napi_finalize)(napi_env env,\n void* finalize_data,\n void* finalize_hint);\n</code></pre>\n",
"type": "module",
"displayName": "napi_finalize"
},
{
"textRaw": "napi_async_execute_callback",
"name": "napi_async_execute_callback",
"desc": "<p>Function pointer used with functions that support asynchronous\noperations. Callback functions must statisfy the following signature:</p>\n<pre><code class=\"lang-C\">typedef void (*napi_async_execute_callback)(napi_env env, void* data);\n</code></pre>\n<p>Implementations of this type of function should avoid making any N-API calls\nthat could result in the execution of JavaScript or interaction with\nJavaScript objects. Most often, any code that needs to make N-API\ncalls should be made in <code>napi_async_complete_callback</code> instead.</p>\n",
"type": "module",
"displayName": "napi_async_execute_callback"
},
{
"textRaw": "napi_async_complete_callback",
"name": "napi_async_complete_callback",
"desc": "<p>Function pointer used with functions that support asynchronous\noperations. Callback functions must statisfy the following signature:</p>\n<pre><code class=\"lang-C\">typedef void (*napi_async_complete_callback)(napi_env env,\n napi_status status,\n void* data);\n</code></pre>\n",
"type": "module",
"displayName": "napi_async_complete_callback"
},
{
"textRaw": "napi_threadsafe_function_call_js",
"name": "napi_threadsafe_function_call_js",
"stability": 1,
"stabilityText": "Experimental",
"desc": "<p>Function pointer used with asynchronous thread-safe function calls. The callback\nwill be called on the main thread. Its purpose is to use a data item arriving\nvia the queue from one of the secondary threads to construct the parameters\nnecessary for a call into JavaScript, usually via <code>napi_call_function</code>, and then\nmake the call into JavaScript.</p>\n<p>The data arriving from the secondary thread via the queue is given in the <code>data</code>\nparameter and the JavaScript function to call is given in the <code>js_callback</code>\nparameter.</p>\n<p>N-API sets up the environment prior to calling this callback, so it is\nsufficient to call the JavaScript function via <code>napi_call_function</code> rather than\nvia <code>napi_make_callback</code>.</p>\n<p>Callback functions must satisfy the following signature:</p>\n<pre><code class=\"lang-C\">typedef void (*napi_threadsafe_function_call_js)(napi_env env,\n napi_value js_callback,\n void* context,\n void* data);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment to use for API calls, or <code>NULL</code> if the thread-safe\nfunction is being torn down and <code>data</code> may need to be freed.</li>\n<li><code>[in] js_callback</code>: The JavaScript function to call, or <code>NULL</code> if the\nthread-safe function is being torn down and <code>data</code> may need to be freed.</li>\n<li><code>[in] context</code>: The optional data with which the thread-safe function was\ncreated.</li>\n<li><code>[in] data</code>: Data created by the secondary thread. It is the responsibility of\nthe callback to convert this native data to JavaScript values (with N-API\nfunctions) that can be passed as parameters when <code>js_callback</code> is invoked. This\npointer is managed entirely by the threads and this callback. Thus this callback\nshould free the data.</li>\n</ul>\n",
"type": "module",
"displayName": "napi_threadsafe_function_call_js"
}
],
"type": "module",
"displayName": "N-API Callback types"
}
],
"type": "misc",
"displayName": "Basic N-API Data Types"
},
{
"textRaw": "Error Handling",
"name": "error_handling",
"desc": "<p>N-API uses both return values and JavaScript exceptions for error handling.\nThe following sections explain the approach for each case.</p>\n",
"modules": [
{
"textRaw": "Return values",
"name": "return_values",
"desc": "<p>All of the N-API functions share the same error handling pattern. The\nreturn type of all API functions is <code>napi_status</code>.</p>\n<p>The return value will be <code>napi_ok</code> if the request was successful and\nno uncaught JavaScript exception was thrown. If an error occurred AND\nan exception was thrown, the <code>napi_status</code> value for the error\nwill be returned. If an exception was thrown, and no error occurred,\n<code>napi_pending_exception</code> will be returned.</p>\n<p>In cases where a return value other than <code>napi_ok</code> or\n<code>napi_pending_exception</code> is returned, <a href=\"#n_api_napi_is_exception_pending\"><code>napi_is_exception_pending</code></a>\nmust be called to check if an exception is pending.\nSee the section on exceptions for more details.</p>\n<p>The full set of possible <code>napi_status</code> values is defined\nin <code>napi_api_types.h</code>.</p>\n<p>The <code>napi_status</code> return value provides a VM-independent representation of\nthe error which occurred. In some cases it is useful to be able to get\nmore detailed information, including a string representing the error as well as\nVM (engine)-specific information.</p>\n<p>In order to retrieve this information <a href=\"#n_api_napi_get_last_error_info\"><code>napi_get_last_error_info</code></a>\nis provided which returns a <code>napi_extended_error_info</code> structure.\nThe format of the <code>napi_extended_error_info</code> structure is as follows:</p>\n<pre><code class=\"lang-C\">typedef struct napi_extended_error_info {\n const char* error_message;\n void* engine_reserved;\n uint32_t engine_error_code;\n napi_status error_code;\n};\n</code></pre>\n<ul>\n<li><code>error_message</code>: Textual representation of the error that occurred.</li>\n<li><code>engine_reserved</code>: Opaque handle reserved for engine use only.</li>\n<li><code>engine_error_code</code>: VM specific error code.</li>\n<li><code>error_code</code>: n-api status code for the last error.</li>\n</ul>\n<p><a href=\"#n_api_napi_get_last_error_info\"><code>napi_get_last_error_info</code></a> returns the information for the last\nN-API call that was made.</p>\n<p>Do not rely on the content or format of any of the extended information as it\nis not subject to SemVer and may change at any time. It is intended only for\nlogging purposes.</p>\n",
"modules": [
{
"textRaw": "napi_get_last_error_info",
"name": "napi_get_last_error_info",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status\nnapi_get_last_error_info(napi_env env,\n const napi_extended_error_info** result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[out] result</code>: The <code>napi_extended_error_info</code> structure with more\ninformation about the error.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API retrieves a <code>napi_extended_error_info</code> structure with information\nabout the last error that occurred.</p>\n<p>The content of the <code>napi_extended_error_info</code> returned is only valid up until\nan n-api function is called on the same <code>env</code>.</p>\n<p>Do not rely on the content or format of any of the extended information as it\nis not subject to SemVer and may change at any time. It is intended only for\nlogging purposes.</p>\n<p>This API can be called even if there is a pending JavaScript exception.</p>\n",
"type": "module",
"displayName": "napi_get_last_error_info"
}
],
"type": "module",
"displayName": "Return values"
},
{
"textRaw": "Exceptions",
"name": "exceptions",
"desc": "<p>Any N-API function call may result in a pending JavaScript exception. This is\nobviously the case for any function that may cause the execution of\nJavaScript, but N-API specifies that an exception may be pending\non return from any of the API functions.</p>\n<p>If the <code>napi_status</code> returned by a function is <code>napi_ok</code> then no\nexception is pending and no additional action is required. If the\n<code>napi_status</code> returned is anything other than <code>napi_ok</code> or\n<code>napi_pending_exception</code>, in order to try to recover and continue\ninstead of simply returning immediately, <a href=\"#n_api_napi_is_exception_pending\"><code>napi_is_exception_pending</code></a>\nmust be called in order to determine if an exception is pending or not.</p>\n<p>When an exception is pending one of two approaches can be employed.</p>\n<p>The first approach is to do any appropriate cleanup and then return so that\nexecution will return to JavaScript. As part of the transition back to\nJavaScript the exception will be thrown at the point in the JavaScript\ncode where the native method was invoked. The behavior of most N-API calls\nis unspecified while an exception is pending, and many will simply return\n<code>napi_pending_exception</code>, so it is important to do as little as possible\nand then return to JavaScript where the exception can be handled.</p>\n<p>The second approach is to try to handle the exception. There will be cases\nwhere the native code can catch the exception, take the appropriate action,\nand then continue. This is only recommended in specific cases\nwhere it is known that the exception can be safely handled. In these\ncases <a href=\"#n_api_napi_get_and_clear_last_exception\"><code>napi_get_and_clear_last_exception</code></a> can be used to get and\nclear the exception. On success, result will contain the handle to\nthe last JavaScript <code>Object</code> thrown. If it is determined, after\nretrieving the exception, the exception cannot be handled after all\nit can be re-thrown it with <a href=\"#n_api_napi_throw\"><code>napi_throw</code></a> where error is the\nJavaScript <code>Error</code> object to be thrown.</p>\n<p>The following utility functions are also available in case native code\nneeds to throw an exception or determine if a <code>napi_value</code> is an instance\nof a JavaScript <code>Error</code> object: <a href=\"#n_api_napi_throw_error\"><code>napi_throw_error</code></a>,\n<a href=\"#n_api_napi_throw_type_error\"><code>napi_throw_type_error</code></a>, <a href=\"#n_api_napi_throw_range_error\"><code>napi_throw_range_error</code></a> and\n<a href=\"#n_api_napi_is_error\"><code>napi_is_error</code></a>.</p>\n<p>The following utility functions are also available in case native\ncode needs to create an <code>Error</code> object: <a href=\"#n_api_napi_create_error\"><code>napi_create_error</code></a>,\n<a href=\"#n_api_napi_create_type_error\"><code>napi_create_type_error</code></a>, and <a href=\"#n_api_napi_create_range_error\"><code>napi_create_range_error</code></a>,\nwhere result is the <code>napi_value</code> that refers to the newly created\nJavaScript <code>Error</code> object.</p>\n<p>The Node.js project is adding error codes to all of the errors\ngenerated internally. The goal is for applications to use these\nerror codes for all error checking. The associated error messages\nwill remain, but will only be meant to be used for logging and\ndisplay with the expectation that the message can change without\nSemVer applying. In order to support this model with N-API, both\nin internal functionality and for module specific functionality\n(as its good practice), the <code>throw_</code> and <code>create_</code> functions\ntake an optional code parameter which is the string for the code\nto be added to the error object. If the optional parameter is NULL\nthen no code will be associated with the error. If a code is provided,\nthe name associated with the error is also updated to be:</p>\n<pre><code class=\"lang-text\">originalName [code]\n</code></pre>\n<p>where <code>originalName</code> is the original name associated with the error\nand <code>code</code> is the code that was provided. For example if the code\nis <code>&#39;ERR_ERROR_1&#39;</code> and a <code>TypeError</code> is being created the name will be:</p>\n<pre><code class=\"lang-text\">TypeError [ERR_ERROR_1]\n</code></pre>\n",
"modules": [
{
"textRaw": "napi_throw",
"name": "napi_throw",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_throw(napi_env env, napi_value error);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] error</code>: The JavaScript value to be thrown.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API throws the JavaScript value provided.</p>\n",
"type": "module",
"displayName": "napi_throw"
},
{
"textRaw": "napi_throw_error",
"name": "napi_throw_error",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_throw_error(napi_env env,\n const char* code,\n const char* msg);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] code</code>: Optional error code to be set on the error.</li>\n<li><code>[in] msg</code>: C string representing the text to be associated with\nthe error.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API throws a JavaScript <code>Error</code> with the text provided.</p>\n",
"type": "module",
"displayName": "napi_throw_error"
},
{
"textRaw": "napi_throw_type_error",
"name": "napi_throw_type_error",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_throw_type_error(napi_env env,\n const char* code,\n const char* msg);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] code</code>: Optional error code to be set on the error.</li>\n<li><code>[in] msg</code>: C string representing the text to be associated with\nthe error.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API throws a JavaScript <code>TypeError</code> with the text provided.</p>\n",
"type": "module",
"displayName": "napi_throw_type_error"
},
{
"textRaw": "napi_throw_range_error",
"name": "napi_throw_range_error",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_throw_range_error(napi_env env,\n const char* code,\n const char* msg);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] code</code>: Optional error code to be set on the error.</li>\n<li><code>[in] msg</code>: C string representing the text to be associated with\nthe error.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API throws a JavaScript <code>RangeError</code> with the text provided.</p>\n",
"type": "module",
"displayName": "napi_throw_range_error"
},
{
"textRaw": "napi_is_error",
"name": "napi_is_error",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_is_error(napi_env env,\n napi_value value,\n bool* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] msg</code>: The <code>napi_value</code> to be checked.</li>\n<li><code>[out] result</code>: Boolean value that is set to true if <code>napi_value</code> represents\nan error, false otherwise.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API queries a <code>napi_value</code> to check if it represents an error object.</p>\n",
"type": "module",
"displayName": "napi_is_error"
},
{
"textRaw": "napi_create_error",
"name": "napi_create_error",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_create_error(napi_env env,\n napi_value code,\n napi_value msg,\n napi_value* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] code</code>: Optional <code>napi_value</code> with the string for the error code to\nbe associated with the error.</li>\n<li><code>[in] msg</code>: <code>napi_value</code> that references a JavaScript <code>String</code> to be\nused as the message for the <code>Error</code>.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing the error created.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns a JavaScript <code>Error</code> with the text provided.</p>\n",
"type": "module",
"displayName": "napi_create_error"
},
{
"textRaw": "napi_create_type_error",
"name": "napi_create_type_error",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_create_type_error(napi_env env,\n napi_value code,\n napi_value msg,\n napi_value* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] code</code>: Optional <code>napi_value</code> with the string for the error code to\nbe associated with the error.</li>\n<li><code>[in] msg</code>: <code>napi_value</code> that references a JavaScript <code>String</code> to be\nused as the message for the <code>Error</code>.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing the error created.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns a JavaScript <code>TypeError</code> with the text provided.</p>\n",
"type": "module",
"displayName": "napi_create_type_error"
},
{
"textRaw": "napi_create_range_error",
"name": "napi_create_range_error",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_create_range_error(napi_env env,\n napi_value code,\n napi_value msg,\n napi_value* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] code</code>: Optional <code>napi_value</code> with the string for the error code to\nbe associated with the error.</li>\n<li><code>[in] msg</code>: <code>napi_value</code> that references a JavaScript <code>String</code> to be\nused as the message for the <code>Error</code>.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing the error created.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns a JavaScript <code>RangeError</code> with the text provided.</p>\n",
"type": "module",
"displayName": "napi_create_range_error"
},
{
"textRaw": "napi_get_and_clear_last_exception",
"name": "napi_get_and_clear_last_exception",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_and_clear_last_exception(napi_env env,\n napi_value* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[out] result</code>: The exception if one is pending, NULL otherwise.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns true if an exception is pending.</p>\n<p>This API can be called even if there is a pending JavaScript exception.</p>\n",
"type": "module",
"displayName": "napi_get_and_clear_last_exception"
},
{
"textRaw": "napi_is_exception_pending",
"name": "napi_is_exception_pending",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_is_exception_pending(napi_env env, bool* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[out] result</code>: Boolean value that is set to true if an exception is pending.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns true if an exception is pending.</p>\n<p>This API can be called even if there is a pending JavaScript exception.</p>\n",
"type": "module",
"displayName": "napi_is_exception_pending"
},
{
"textRaw": "napi_fatal_exception",
"name": "napi_fatal_exception",
"meta": {
"added": [
"v9.10.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_fatal_exception(napi_env env, napi_value err);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] err</code>: The error that is passed to <code>&#39;uncaughtException&#39;</code>.</li>\n</ul>\n<p>Trigger an <code>&#39;uncaughtException&#39;</code> in JavaScript. Useful if an async\ncallback throws an exception with no way to recover.</p>\n",
"type": "module",
"displayName": "napi_fatal_exception"
}
],
"type": "module",
"displayName": "Exceptions"
},
{
"textRaw": "Fatal Errors",
"name": "fatal_errors",
"desc": "<p>In the event of an unrecoverable error in a native module, a fatal error can be\nthrown to immediately terminate the process.</p>\n",
"modules": [
{
"textRaw": "napi_fatal_error",
"name": "napi_fatal_error",
"meta": {
"added": [
"v8.2.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_NO_RETURN void napi_fatal_error(const char* location,\n size_t location_len,\n const char* message,\n size_t message_len);\n</code></pre>\n<ul>\n<li><code>[in] location</code>: Optional location at which the error occurred.</li>\n<li><code>[in] location_len</code>: The length of the location in bytes, or\n<code>NAPI_AUTO_LENGTH</code> if it is null-terminated.</li>\n<li><code>[in] message</code>: The message associated with the error.</li>\n<li><code>[in] message_len</code>: The length of the message in bytes, or\n<code>NAPI_AUTO_LENGTH</code> if it is\nnull-terminated.</li>\n</ul>\n<p>The function call does not return, the process will be terminated.</p>\n<p>This API can be called even if there is a pending JavaScript exception.</p>\n",
"type": "module",
"displayName": "napi_fatal_error"
}
],
"type": "module",
"displayName": "Fatal Errors"
}
],
"type": "misc",
"displayName": "Error Handling"
},
{
"textRaw": "Object Lifetime management",
"name": "object_lifetime_management",
"desc": "<p>As N-API calls are made, handles to objects in the heap for the underlying\nVM may be returned as <code>napi_values</code>. These handles must hold the\nobjects &#39;live&#39; until they are no longer required by the native code,\notherwise the objects could be collected before the native code was\nfinished using them.</p>\n<p>As object handles are returned they are associated with a\n&#39;scope&#39;. The lifespan for the default scope is tied to the lifespan\nof the native method call. The result is that, by default, handles\nremain valid and the objects associated with these handles will be\nheld live for the lifespan of the native method call.</p>\n<p>In many cases, however, it is necessary that the handles remain valid for\neither a shorter or longer lifespan than that of the native method.\nThe sections which follow describe the N-API functions that can be used\nto change the handle lifespan from the default.</p>\n",
"modules": [
{
"textRaw": "Making handle lifespan shorter than that of the native method",
"name": "making_handle_lifespan_shorter_than_that_of_the_native_method",
"desc": "<p>It is often necessary to make the lifespan of handles shorter than\nthe lifespan of a native method. For example, consider a native method\nthat has a loop which iterates through the elements in a large array:</p>\n<pre><code class=\"lang-C\">for (int i = 0; i &lt; 1000000; i++) {\n napi_value result;\n napi_status status = napi_get_element(env, object, i, &amp;result);\n if (status != napi_ok) {\n break;\n }\n // do something with element\n}\n</code></pre>\n<p>This would result in a large number of handles being created, consuming\nsubstantial resources. In addition, even though the native code could only\nuse the most recent handle, all of the associated objects would also be\nkept alive since they all share the same scope.</p>\n<p>To handle this case, N-API provides the ability to establish a new &#39;scope&#39; to\nwhich newly created handles will be associated. Once those handles\nare no longer required, the scope can be &#39;closed&#39; and any handles associated\nwith the scope are invalidated. The methods available to open/close scopes are\n<a href=\"#n_api_napi_open_handle_scope\"><code>napi_open_handle_scope</code></a> and <a href=\"#n_api_napi_close_handle_scope\"><code>napi_close_handle_scope</code></a>.</p>\n<p>N-API only supports a single nested hierarchy of scopes. There is only one\nactive scope at any time, and all new handles will be associated with that\nscope while it is active. Scopes must be closed in the reverse order from\nwhich they are opened. In addition, all scopes created within a native method\nmust be closed before returning from that method.</p>\n<p>Taking the earlier example, adding calls to <a href=\"#n_api_napi_open_handle_scope\"><code>napi_open_handle_scope</code></a> and\n<a href=\"#n_api_napi_close_handle_scope\"><code>napi_close_handle_scope</code></a> would ensure that at most a single handle\nis valid throughout the execution of the loop:</p>\n<pre><code class=\"lang-C\">for (int i = 0; i &lt; 1000000; i++) {\n napi_handle_scope scope;\n napi_status status = napi_open_handle_scope(env, &amp;scope);\n if (status != napi_ok) {\n break;\n }\n napi_value result;\n status = napi_get_element(env, object, i, &amp;result);\n if (status != napi_ok) {\n break;\n }\n // do something with element\n status = napi_close_handle_scope(env, scope);\n if (status != napi_ok) {\n break;\n }\n}\n</code></pre>\n<p>When nesting scopes, there are cases where a handle from an\ninner scope needs to live beyond the lifespan of that scope. N-API supports an\n&#39;escapable scope&#39; in order to support this case. An escapable scope\nallows one handle to be &#39;promoted&#39; so that it &#39;escapes&#39; the\ncurrent scope and the lifespan of the handle changes from the current\nscope to that of the outer scope.</p>\n<p>The methods available to open/close escapable scopes are\n<a href=\"#n_api_napi_open_escapable_handle_scope\"><code>napi_open_escapable_handle_scope</code></a> and\n<a href=\"#n_api_napi_close_escapable_handle_scope\"><code>napi_close_escapable_handle_scope</code></a>.</p>\n<p>The request to promote a handle is made through <a href=\"#n_api_napi_escape_handle\"><code>napi_escape_handle</code></a> which\ncan only be called once.</p>\n",
"modules": [
{
"textRaw": "napi_open_handle_scope",
"name": "napi_open_handle_scope",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_open_handle_scope(napi_env env,\n napi_handle_scope* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing the new scope.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API open a new scope.</p>\n",
"type": "module",
"displayName": "napi_open_handle_scope"
},
{
"textRaw": "napi_close_handle_scope",
"name": "napi_close_handle_scope",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_close_handle_scope(napi_env env,\n napi_handle_scope scope);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] scope</code>: <code>napi_value</code> representing the scope to be closed.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API closes the scope passed in. Scopes must be closed in the\nreverse order from which they were created.</p>\n<p>This API can be called even if there is a pending JavaScript exception.</p>\n",
"type": "module",
"displayName": "napi_close_handle_scope"
},
{
"textRaw": "napi_open_escapable_handle_scope",
"name": "napi_open_escapable_handle_scope",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status\n napi_open_escapable_handle_scope(napi_env env,\n napi_handle_scope* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing the new scope.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API open a new scope from which one object can be promoted\nto the outer scope.</p>\n",
"type": "module",
"displayName": "napi_open_escapable_handle_scope"
},
{
"textRaw": "napi_close_escapable_handle_scope",
"name": "napi_close_escapable_handle_scope",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status\n napi_close_escapable_handle_scope(napi_env env,\n napi_handle_scope scope);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] scope</code>: <code>napi_value</code> representing the scope to be closed.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API closes the scope passed in. Scopes must be closed in the\nreverse order from which they were created.</p>\n<p>This API can be called even if there is a pending JavaScript exception.</p>\n",
"type": "module",
"displayName": "napi_close_escapable_handle_scope"
},
{
"textRaw": "napi_escape_handle",
"name": "napi_escape_handle",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_escape_handle(napi_env env,\n napi_escapable_handle_scope scope,\n napi_value escapee,\n napi_value* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] scope</code>: <code>napi_value</code> representing the current scope.</li>\n<li><code>[in] escapee</code>: <code>napi_value</code> representing the JavaScript <code>Object</code> to be\nescaped.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing the handle to the escaped\n<code>Object</code> in the outer scope.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API promotes the handle to the JavaScript object so that it is valid\nfor the lifetime of the outer scope. It can only be called once per scope.\nIf it is called more than once an error will be returned.</p>\n<p>This API can be called even if there is a pending JavaScript exception.</p>\n",
"type": "module",
"displayName": "napi_escape_handle"
}
],
"type": "module",
"displayName": "Making handle lifespan shorter than that of the native method"
},
{
"textRaw": "References to objects with a lifespan longer than that of the native method",
"name": "references_to_objects_with_a_lifespan_longer_than_that_of_the_native_method",
"desc": "<p>In some cases an addon will need to be able to create and reference objects\nwith a lifespan longer than that of a single native method invocation. For\nexample, to create a constructor and later use that constructor\nin a request to creates instances, it must be possible to reference\nthe constructor object across many different instance creation requests. This\nwould not be possible with a normal handle returned as a <code>napi_value</code> as\ndescribed in the earlier section. The lifespan of a normal handle is\nmanaged by scopes and all scopes must be closed before the end of a native\nmethod.</p>\n<p>N-API provides methods to create persistent references to an object.\nEach persistent reference has an associated count with a value of 0\nor higher. The count determines if the reference will keep\nthe corresponding object live. References with a count of 0 do not\nprevent the object from being collected and are often called &#39;weak&#39;\nreferences. Any count greater than 0 will prevent the object\nfrom being collected.</p>\n<p>References can be created with an initial reference count. The count can\nthen be modified through <a href=\"#n_api_napi_reference_ref\"><code>napi_reference_ref</code></a> and\n<a href=\"#n_api_napi_reference_unref\"><code>napi_reference_unref</code></a>. If an object is collected while the count\nfor a reference is 0, all subsequent calls to\nget the object associated with the reference <a href=\"#n_api_napi_get_reference_value\"><code>napi_get_reference_value</code></a>\nwill return NULL for the returned <code>napi_value</code>. An attempt to call\n<a href=\"#n_api_napi_reference_ref\"><code>napi_reference_ref</code></a> for a reference whose object has been collected\nwill result in an error.</p>\n<p>References must be deleted once they are no longer required by the addon. When\na reference is deleted it will no longer prevent the corresponding object from\nbeing collected. Failure to delete a persistent reference will result in\na &#39;memory leak&#39; with both the native memory for the persistent reference and\nthe corresponding object on the heap being retained forever.</p>\n<p>There can be multiple persistent references created which refer to the same\nobject, each of which will either keep the object live or not based on its\nindividual count.</p>\n",
"modules": [
{
"textRaw": "napi_create_reference",
"name": "napi_create_reference",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_create_reference(napi_env env,\n napi_value value,\n int initial_refcount,\n napi_ref* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: <code>napi_value</code> representing the <code>Object</code> to which we want\na reference.</li>\n<li><code>[in] initial_refcount</code>: Initial reference count for the new reference.</li>\n<li><code>[out] result</code>: <code>napi_ref</code> pointing to the new reference.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API create a new reference with the specified reference count\nto the <code>Object</code> passed in.</p>\n",
"type": "module",
"displayName": "napi_create_reference"
},
{
"textRaw": "napi_delete_reference",
"name": "napi_delete_reference",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_delete_reference(napi_env env, napi_ref ref);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] ref</code>: <code>napi_ref</code> to be deleted.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API deletes the reference passed in.</p>\n<p>This API can be called even if there is a pending JavaScript exception.</p>\n",
"type": "module",
"displayName": "napi_delete_reference"
},
{
"textRaw": "napi_reference_ref",
"name": "napi_reference_ref",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_reference_ref(napi_env env,\n napi_ref ref,\n int* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] ref</code>: <code>napi_ref</code> for which the reference count will be incremented.</li>\n<li><code>[out] result</code>: The new reference count.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API increments the reference count for the reference\npassed in and returns the resulting reference count.</p>\n",
"type": "module",
"displayName": "napi_reference_ref"
},
{
"textRaw": "napi_reference_unref",
"name": "napi_reference_unref",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_reference_unref(napi_env env,\n napi_ref ref,\n int* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] ref</code>: <code>napi_ref</code> for which the reference count will be decremented.</li>\n<li><code>[out] result</code>: The new reference count.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API decrements the reference count for the reference\npassed in and returns the resulting reference count.</p>\n",
"type": "module",
"displayName": "napi_reference_unref"
},
{
"textRaw": "napi_get_reference_value",
"name": "napi_get_reference_value",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_get_reference_value(napi_env env,\n napi_ref ref,\n napi_value* result);\n</code></pre>\n<p>the <code>napi_value passed</code> in or out of these methods is a handle to the\nobject to which the reference is related.</p>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] ref</code>: <code>napi_ref</code> for which we requesting the corresponding <code>Object</code>.</li>\n<li><code>[out] result</code>: The <code>napi_value</code> for the <code>Object</code> referenced by the\n<code>napi_ref</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>If still valid, this API returns the <code>napi_value</code> representing the\nJavaScript <code>Object</code> associated with the <code>napi_ref</code>. Otherwise, result\nwill be NULL.</p>\n",
"type": "module",
"displayName": "napi_get_reference_value"
}
],
"type": "module",
"displayName": "References to objects with a lifespan longer than that of the native method"
},
{
"textRaw": "Cleanup on exit of the current Node.js instance",
"name": "cleanup_on_exit_of_the_current_node.js_instance",
"desc": "<p>While a Node.js process typically releases all its resources when exiting,\nembedders of Node.js, or future Worker support, may require addons to register\nclean-up hooks that will be run once the current Node.js instance exits.</p>\n<p>N-API provides functions for registering and un-registering such callbacks.\nWhen those callbacks are run, all resources that are being held by the addon\nshould be freed up.</p>\n",
"modules": [
{
"textRaw": "napi_add_env_cleanup_hook",
"name": "napi_add_env_cleanup_hook",
"meta": {
"added": [
"v10.2.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NODE_EXTERN napi_status napi_add_env_cleanup_hook(napi_env env,\n void (*fun)(void* arg),\n void* arg);\n</code></pre>\n<p>Registers <code>fun</code> as a function to be run with the <code>arg</code> parameter once the\ncurrent Node.js environment exits.</p>\n<p>A function can safely be specified multiple times with different\n<code>arg</code> values. In that case, it will be called multiple times as well.\nProviding the same <code>fun</code> and <code>arg</code> values multiple times is not allowed\nand will lead the process to abort.</p>\n<p>The hooks will be called in reverse order, i.e. the most recently added one\nwill be called first.</p>\n<p>Removing this hook can be done by using <code>napi_remove_env_cleanup_hook</code>.\nTypically, that happens when the resource for which this hook was added\nis being torn down anyway.</p>\n",
"type": "module",
"displayName": "napi_add_env_cleanup_hook"
},
{
"textRaw": "napi_remove_env_cleanup_hook",
"name": "napi_remove_env_cleanup_hook",
"meta": {
"added": [
"v10.2.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_remove_env_cleanup_hook(napi_env env,\n void (*fun)(void* arg),\n void* arg);\n</code></pre>\n<p>Unregisters <code>fun</code> as a function to be run with the <code>arg</code> parameter once the\ncurrent Node.js environment exits. Both the argument and the function value\nneed to be exact matches.</p>\n<p>The function must have originally been registered\nwith <code>napi_add_env_cleanup_hook</code>, otherwise the process will abort.</p>\n",
"type": "module",
"displayName": "napi_remove_env_cleanup_hook"
}
],
"type": "module",
"displayName": "Cleanup on exit of the current Node.js instance"
}
],
"type": "misc",
"displayName": "Object Lifetime management"
},
{
"textRaw": "Module registration",
"name": "module_registration",
"desc": "<p>N-API modules are registered in a manner similar to other modules\nexcept that instead of using the <code>NODE_MODULE</code> macro the following\nis used:</p>\n<pre><code class=\"lang-C\">NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)\n</code></pre>\n<p>The next difference is the signature for the <code>Init</code> method. For a N-API\nmodule it is as follows:</p>\n<pre><code class=\"lang-C\">napi_value Init(napi_env env, napi_value exports);\n</code></pre>\n<p>The return value from <code>Init</code> is treated as the <code>exports</code> object for the module.\nThe <code>Init</code> method is passed an empty object via the <code>exports</code> parameter as a\nconvenience. If <code>Init</code> returns NULL, the parameter passed as <code>exports</code> is\nexported by the module. N-API modules cannot modify the <code>module</code> object but can\nspecify anything as the <code>exports</code> property of the module.</p>\n<p>To add the method <code>hello</code> as a function so that it can be called as a method\nprovided by the addon:</p>\n<pre><code class=\"lang-C\">napi_value Init(napi_env env, napi_value exports) {\n napi_status status;\n napi_property_descriptor desc =\n {&quot;hello&quot;, NULL, Method, NULL, NULL, NULL, napi_default, NULL};\n status = napi_define_properties(env, exports, 1, &amp;desc);\n if (status != napi_ok) return NULL;\n return exports;\n}\n</code></pre>\n<p>To set a function to be returned by the <code>require()</code> for the addon:</p>\n<pre><code class=\"lang-C\">napi_value Init(napi_env env, napi_value exports) {\n napi_value method;\n napi_status status;\n status = napi_create_function(env, &quot;exports&quot;, NAPI_AUTO_LENGTH, Method, NULL, &amp;method);\n if (status != napi_ok) return NULL;\n return method;\n}\n</code></pre>\n<p>To define a class so that new instances can be created (often used with\n<a href=\"#n_api_object_wrap\">Object Wrap</a>):</p>\n<pre><code class=\"lang-C\">// NOTE: partial example, not all referenced code is included\nnapi_value Init(napi_env env, napi_value exports) {\n napi_status status;\n napi_property_descriptor properties[] = {\n { &quot;value&quot;, NULL, NULL, GetValue, SetValue, NULL, napi_default, NULL },\n DECLARE_NAPI_METHOD(&quot;plusOne&quot;, PlusOne),\n DECLARE_NAPI_METHOD(&quot;multiply&quot;, Multiply),\n };\n\n napi_value cons;\n status =\n napi_define_class(env, &quot;MyObject&quot;, New, NULL, 3, properties, &amp;cons);\n if (status != napi_ok) return NULL;\n\n status = napi_create_reference(env, cons, 1, &amp;constructor);\n if (status != napi_ok) return NULL;\n\n status = napi_set_named_property(env, exports, &quot;MyObject&quot;, cons);\n if (status != napi_ok) return NULL;\n\n return exports;\n}\n</code></pre>\n<p>If the module will be loaded multiple times during the lifetime of the Node.js\nprocess, use the <code>NAPI_MODULE_INIT</code> macro to initialize the module:</p>\n<pre><code class=\"lang-C\">NAPI_MODULE_INIT() {\n napi_value answer;\n napi_status result;\n\n status = napi_create_int64(env, 42, &amp;answer);\n if (status != napi_ok) return NULL;\n\n status = napi_set_named_property(env, exports, &quot;answer&quot;, answer);\n if (status != napi_ok) return NULL;\n\n return exports;\n}\n</code></pre>\n<p>This macro includes <code>NAPI_MODULE</code>, and declares an <code>Init</code> function with a\nspecial name and with visibility beyond the addon. This will allow Node.js to\ninitialize the module even if it is loaded multiple times.</p>\n<p>The variables <code>env</code> and <code>exports</code> will be available inside the function body\nfollowing the macro invocation.</p>\n<p>For more details on setting properties on objects, see the section on\n<a href=\"#n_api_working_with_javascript_properties\">Working with JavaScript Properties</a>.</p>\n<p>For more details on building addon modules in general, refer to the existing\nAPI.</p>\n",
"type": "misc",
"displayName": "Module registration"
},
{
"textRaw": "Working with JavaScript Values",
"name": "working_with_javascript_values",
"desc": "<p>N-API exposes a set of APIs to create all types of JavaScript values.\nSome of these types are documented under\n<a href=\"https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values\">Section 6</a>\nof the <a href=\"https://tc39.github.io/ecma262/\">ECMAScript Language Specification</a>.</p>\n<p>Fundamentally, these APIs are used to do one of the following:</p>\n<ol>\n<li>Create a new JavaScript object</li>\n<li>Convert from a primitive C type to an N-API value</li>\n<li>Convert from N-API value to a primitive C type</li>\n<li>Get global instances including <code>undefined</code> and <code>null</code></li>\n</ol>\n<p>N-API values are represented by the type <code>napi_value</code>.\nAny N-API call that requires a JavaScript value takes in a <code>napi_value</code>.\nIn some cases, the API does check the type of the <code>napi_value</code> up-front.\nHowever, for better performance, it&#39;s better for the caller to make sure that\nthe <code>napi_value</code> in question is of the JavaScript type expected by the API.</p>\n",
"modules": [
{
"textRaw": "Enum types",
"name": "enum_types",
"modules": [
{
"textRaw": "napi_valuetype",
"name": "napi_valuetype",
"desc": "<pre><code class=\"lang-C\">typedef enum {\n // ES6 types (corresponds to typeof)\n napi_undefined,\n napi_null,\n napi_boolean,\n napi_number,\n napi_string,\n napi_symbol,\n napi_object,\n napi_function,\n napi_external,\n} napi_valuetype;\n</code></pre>\n<p>Describes the type of a <code>napi_value</code>. This generally corresponds to the types\ndescribed in\n<a href=\"https://tc39.github.io/ecma262/#sec-ecmascript-language-types\">Section 6.1</a> of\nthe ECMAScript Language Specification.\nIn addition to types in that section, <code>napi_valuetype</code> can also represent\n<code>Function</code>s and <code>Object</code>s with external data.</p>\n<p>A JavaScript value of type <code>napi_external</code> appears in JavaScript as a plain\nobject such that no properties can be set on it, and no prototype.</p>\n",
"type": "module",
"displayName": "napi_valuetype"
},
{
"textRaw": "napi_typedarray_type",
"name": "napi_typedarray_type",
"desc": "<pre><code class=\"lang-C\">typedef enum {\n napi_int8_array,\n napi_uint8_array,\n napi_uint8_clamped_array,\n napi_int16_array,\n napi_uint16_array,\n napi_int32_array,\n napi_uint32_array,\n napi_float32_array,\n napi_float64_array,\n} napi_typedarray_type;\n</code></pre>\n<p>This represents the underlying binary scalar datatype of the <code>TypedArray</code>.\nElements of this enum correspond to\n<a href=\"https://tc39.github.io/ecma262/#sec-typedarray-objects\">Section 22.2</a> of the <a href=\"https://tc39.github.io/ecma262/\">ECMAScript Language Specification</a>.</p>\n",
"type": "module",
"displayName": "napi_typedarray_type"
}
],
"type": "module",
"displayName": "Enum types"
},
{
"textRaw": "Object Creation Functions",
"name": "object_creation_functions",
"modules": [
{
"textRaw": "napi_create_array",
"name": "napi_create_array",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_array(napi_env env, napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the N-API call is invoked under.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>Array</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns an N-API value corresponding to a JavaScript <code>Array</code> type.\nJavaScript arrays are described in\n<a href=\"https://tc39.github.io/ecma262/#sec-array-objects\">Section 22.1</a> of the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_create_array"
},
{
"textRaw": "napi_create_array_with_length",
"name": "napi_create_array_with_length",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_array_with_length(napi_env env,\n size_t length,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] length</code>: The initial length of the <code>Array</code>.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>Array</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns an N-API value corresponding to a JavaScript <code>Array</code> type.\nThe <code>Array</code>&#39;s length property is set to the passed-in length parameter.\nHowever, the underlying buffer is not guaranteed to be pre-allocated by the VM\nwhen the array is created - that behavior is left to the underlying VM\nimplementation.\nIf the buffer must be a contiguous block of memory that can be\ndirectly read and/or written via C, consider using\n<a href=\"#n_api_napi_create_external_arraybuffer\"><code>napi_create_external_arraybuffer</code></a>.</p>\n<p>JavaScript arrays are described in\n<a href=\"https://tc39.github.io/ecma262/#sec-array-objects\">Section 22.1</a> of the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_create_array_with_length"
},
{
"textRaw": "napi_create_arraybuffer",
"name": "napi_create_arraybuffer",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_arraybuffer(napi_env env,\n size_t byte_length,\n void** data,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] length</code>: The length in bytes of the array buffer to create.</li>\n<li><code>[out] data</code>: Pointer to the underlying byte buffer of the <code>ArrayBuffer</code>.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>ArrayBuffer</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns an N-API value corresponding to a JavaScript <code>ArrayBuffer</code>.\n<code>ArrayBuffer</code>s are used to represent fixed-length binary data buffers. They are\nnormally used as a backing-buffer for <code>TypedArray</code> objects.\nThe <code>ArrayBuffer</code> allocated will have an underlying byte buffer whose size is\ndetermined by the <code>length</code> parameter that&#39;s passed in.\nThe underlying buffer is optionally returned back to the caller in case the\ncaller wants to directly manipulate the buffer. This buffer can only be\nwritten to directly from native code. To write to this buffer from JavaScript,\na typed array or <code>DataView</code> object would need to be created.</p>\n<p>JavaScript <code>ArrayBuffer</code> objects are described in\n<a href=\"https://tc39.github.io/ecma262/#sec-arraybuffer-objects\">Section 24.1</a> of the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_create_arraybuffer"
},
{
"textRaw": "napi_create_buffer",
"name": "napi_create_buffer",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_buffer(napi_env env,\n size_t size,\n void** data,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] size</code>: Size in bytes of the underlying buffer.</li>\n<li><code>[out] data</code>: Raw pointer to the underlying buffer.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a <code>node::Buffer</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API allocates a <code>node::Buffer</code> object. While this is still a\nfully-supported data structure, in most cases using a <code>TypedArray</code> will suffice.</p>\n",
"type": "module",
"displayName": "napi_create_buffer"
},
{
"textRaw": "napi_create_buffer_copy",
"name": "napi_create_buffer_copy",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_buffer_copy(napi_env env,\n size_t length,\n const void* data,\n void** result_data,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] size</code>: Size in bytes of the input buffer (should be the same as the\nsize of the new buffer).</li>\n<li><code>[in] data</code>: Raw pointer to the underlying buffer to copy from.</li>\n<li><code>[out] result_data</code>: Pointer to the new <code>Buffer</code>&#39;s underlying data buffer.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a <code>node::Buffer</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API allocates a <code>node::Buffer</code> object and initializes it with data copied\nfrom the passed-in buffer. While this is still a fully-supported data\nstructure, in most cases using a <code>TypedArray</code> will suffice.</p>\n",
"type": "module",
"displayName": "napi_create_buffer_copy"
},
{
"textRaw": "napi_create_external",
"name": "napi_create_external",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_external(napi_env env,\n void* data,\n napi_finalize finalize_cb,\n void* finalize_hint,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] data</code>: Raw pointer to the external data.</li>\n<li><code>[in] finalize_cb</code>: Optional callback to call when the external value\nis being collected.</li>\n<li><code>[in] finalize_hint</code>: Optional hint to pass to the finalize callback\nduring collection.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing an external value.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API allocates a JavaScript value with external data attached to it. This\nis used to pass external data through JavaScript code, so it can be retrieved\nlater by native code. The API allows the caller to pass in a finalize callback,\nin case the underlying native resource needs to be cleaned up when the external\nJavaScript value gets collected.</p>\n<p>The created value is not an object, and therefore does not support additional\nproperties. It is considered a distinct value type: calling <code>napi_typeof()</code> with\nan external value yields <code>napi_external</code>.</p>\n",
"type": "module",
"displayName": "napi_create_external"
},
{
"textRaw": "napi_create_external_arraybuffer",
"name": "napi_create_external_arraybuffer",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status\nnapi_create_external_arraybuffer(napi_env env,\n void* external_data,\n size_t byte_length,\n napi_finalize finalize_cb,\n void* finalize_hint,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] external_data</code>: Pointer to the underlying byte buffer of the\n<code>ArrayBuffer</code>.</li>\n<li><code>[in] byte_length</code>: The length in bytes of the underlying buffer.</li>\n<li><code>[in] finalize_cb</code>: Optional callback to call when the <code>ArrayBuffer</code> is\nbeing collected.</li>\n<li><code>[in] finalize_hint</code>: Optional hint to pass to the finalize callback\nduring collection.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>ArrayBuffer</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns an N-API value corresponding to a JavaScript <code>ArrayBuffer</code>.\nThe underlying byte buffer of the <code>ArrayBuffer</code> is externally allocated and\nmanaged. The caller must ensure that the byte buffer remains valid until the\nfinalize callback is called.</p>\n<p>JavaScript <code>ArrayBuffer</code>s are described in\n<a href=\"https://tc39.github.io/ecma262/#sec-arraybuffer-objects\">Section 24.1</a> of the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_create_external_arraybuffer"
},
{
"textRaw": "napi_create_external_buffer",
"name": "napi_create_external_buffer",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_external_buffer(napi_env env,\n size_t length,\n void* data,\n napi_finalize finalize_cb,\n void* finalize_hint,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] length</code>: Size in bytes of the input buffer (should be the same as\nthe size of the new buffer).</li>\n<li><code>[in] data</code>: Raw pointer to the underlying buffer to copy from.</li>\n<li><code>[in] finalize_cb</code>: Optional callback to call when the <code>ArrayBuffer</code> is\nbeing collected.</li>\n<li><code>[in] finalize_hint</code>: Optional hint to pass to the finalize callback\nduring collection.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a <code>node::Buffer</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API allocates a <code>node::Buffer</code> object and initializes it with data\nbacked by the passed in buffer. While this is still a fully-supported data\nstructure, in most cases using a <code>TypedArray</code> will suffice.</p>\n<p>For Node.js &gt;=4 <code>Buffers</code> are <code>Uint8Array</code>s.</p>\n",
"type": "module",
"displayName": "napi_create_external_buffer"
},
{
"textRaw": "napi_create_function",
"name": "napi_create_function",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_function(napi_env env,\n const char* utf8name,\n size_t length,\n napi_callback cb,\n void* data,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] utf8name</code>: A string representing the name of the function encoded as\nUTF8.</li>\n<li><code>[in] length</code>: The length of the <code>utf8name</code> in bytes, or\n<code>NAPI_AUTO_LENGTH</code> if it is null-terminated.</li>\n<li><code>[in] cb</code>: A function pointer to the native function to be invoked when the\ncreated function is invoked from JavaScript.</li>\n<li><code>[in] data</code>: Optional arbitrary context data to be passed into the native\nfunction when it is invoked.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript function.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns an N-API value corresponding to a JavaScript <code>Function</code> object.\nIt&#39;s used to wrap native functions so that they can be invoked from JavaScript.</p>\n<p>JavaScript <code>Function</code>s are described in\n<a href=\"https://tc39.github.io/ecma262/#sec-function-objects\">Section 19.2</a>\nof the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_create_function"
},
{
"textRaw": "napi_create_object",
"name": "napi_create_object",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_object(napi_env env, napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>Object</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API allocates a default JavaScript <code>Object</code>.\nIt is the equivalent of doing <code>new Object()</code> in JavaScript.</p>\n<p>The JavaScript <code>Object</code> type is described in\n<a href=\"https://tc39.github.io/ecma262/#sec-object-type\">Section 6.1.7</a> of the\nECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_create_object"
},
{
"textRaw": "napi_create_symbol",
"name": "napi_create_symbol",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_symbol(napi_env env,\n napi_value description,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] description</code>: Optional <code>napi_value</code> which refers to a JavaScript\n<code>String</code> to be set as the description for the symbol.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>Symbol</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API creates a JavaScript <code>Symbol</code> object from a UTF8-encoded C string.</p>\n<p>The JavaScript <code>Symbol</code> type is described in\n<a href=\"https://tc39.github.io/ecma262/#sec-symbol-objects\">Section 19.4</a>\nof the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_create_symbol"
},
{
"textRaw": "napi_create_typedarray",
"name": "napi_create_typedarray",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_typedarray(napi_env env,\n napi_typedarray_type type,\n size_t length,\n napi_value arraybuffer,\n size_t byte_offset,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] type</code>: Scalar datatype of the elements within the <code>TypedArray</code>.</li>\n<li><code>[in] length</code>: Number of elements in the <code>TypedArray</code>.</li>\n<li><code>[in] arraybuffer</code>: <code>ArrayBuffer</code> underlying the typed array.</li>\n<li><code>[in] byte_offset</code>: The byte offset within the <code>ArrayBuffer</code> from which to\nstart projecting the <code>TypedArray</code>.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>TypedArray</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API creates a JavaScript <code>TypedArray</code> object over an existing\n<code>ArrayBuffer</code>. <code>TypedArray</code> objects provide an array-like view over an\nunderlying data buffer where each element has the same underlying binary scalar\ndatatype.</p>\n<p>It&#39;s required that <code>(length * size_of_element) + byte_offset</code> should\nbe &lt;= the size in bytes of the array passed in. If not, a <code>RangeError</code> exception\nis raised.</p>\n<p>JavaScript <code>TypedArray</code> objects are described in\n<a href=\"https://tc39.github.io/ecma262/#sec-typedarray-objects\">Section 22.2</a> of the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_create_typedarray"
},
{
"textRaw": "napi_create_dataview",
"name": "napi_create_dataview",
"meta": {
"added": [
"v8.3.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_dataview(napi_env env,\n size_t byte_length,\n napi_value arraybuffer,\n size_t byte_offset,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] length</code>: Number of elements in the <code>DataView</code>.</li>\n<li><code>[in] arraybuffer</code>: <code>ArrayBuffer</code> underlying the <code>DataView</code>.</li>\n<li><code>[in] byte_offset</code>: The byte offset within the <code>ArrayBuffer</code> from which to\nstart projecting the <code>DataView</code>.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>DataView</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API creates a JavaScript <code>DataView</code> object over an existing <code>ArrayBuffer</code>.\n<code>DataView</code> objects provide an array-like view over an underlying data buffer,\nbut one which allows items of different size and type in the <code>ArrayBuffer</code>.</p>\n<p>It is required that <code>byte_length + byte_offset</code> is less than or equal to the\nsize in bytes of the array passed in. If not, a <code>RangeError</code> exception is\nraised.</p>\n<p>JavaScript <code>DataView</code> objects are described in\n<a href=\"https://tc39.github.io/ecma262/#sec-dataview-objects\">Section 24.3</a> of the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_create_dataview"
}
],
"type": "module",
"displayName": "Object Creation Functions"
},
{
"textRaw": "Functions to convert from C types to N-API",
"name": "functions_to_convert_from_c_types_to_n-api",
"modules": [
{
"textRaw": "napi_create_int32",
"name": "napi_create_int32",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_int32(napi_env env, int32_t value, napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: Integer value to be represented in JavaScript.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>Number</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API is used to convert from the C <code>int32_t</code> type to the JavaScript\n<code>Number</code> type.</p>\n<p>The JavaScript <code>Number</code> type is described in\n<a href=\"https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type\">Section 6.1.6</a> of the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_create_int32"
},
{
"textRaw": "napi_create_uint32",
"name": "napi_create_uint32",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_uint32(napi_env env, uint32_t value, napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: Unsigned integer value to be represented in JavaScript.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>Number</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API is used to convert from the C <code>uint32_t</code> type to the JavaScript\n<code>Number</code> type.</p>\n<p>The JavaScript <code>Number</code> type is described in\n<a href=\"https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type\">Section 6.1.6</a> of the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_create_uint32"
},
{
"textRaw": "napi_create_int64",
"name": "napi_create_int64",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_int64(napi_env env, int64_t value, napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: Integer value to be represented in JavaScript.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>Number</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API is used to convert from the C <code>int64_t</code> type to the JavaScript\n<code>Number</code> type.</p>\n<p>The JavaScript <code>Number</code> type is described in <a href=\"https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type\">Section 6.1.6</a>\nof the ECMAScript Language Specification. Note the complete range of <code>int64_t</code>\ncannot be represented with full precision in JavaScript. Integer values\noutside the range of\n<a href=\"https://tc39.github.io/ecma262/#sec-number.min_safe_integer\"><code>Number.MIN_SAFE_INTEGER</code></a>\n-(2^53 - 1) -\n<a href=\"https://tc39.github.io/ecma262/#sec-number.max_safe_integer\"><code>Number.MAX_SAFE_INTEGER</code></a>\n(2^53 - 1) will lose precision.</p>\n",
"type": "module",
"displayName": "napi_create_int64"
},
{
"textRaw": "napi_create_double",
"name": "napi_create_double",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_double(napi_env env, double value, napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: Double-precision value to be represented in JavaScript.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>Number</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API is used to convert from the C <code>double</code> type to the JavaScript\n<code>Number</code> type.</p>\n<p>The JavaScript <code>Number</code> type is described in\n<a href=\"https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type\">Section 6.1.6</a> of the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_create_double"
},
{
"textRaw": "napi_create_string_latin1",
"name": "napi_create_string_latin1",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_string_latin1(napi_env env,\n const char* str,\n size_t length,\n napi_value* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] str</code>: Character buffer representing an ISO-8859-1-encoded string.</li>\n<li><code>[in] length</code>: The length of the string in bytes, or\n<code>NAPI_AUTO_LENGTH</code> if it is null-terminated.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>String</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API creates a JavaScript <code>String</code> object from an ISO-8859-1-encoded C\nstring. The native string is copied.</p>\n<p>The JavaScript <code>String</code> type is described in\n<a href=\"https://tc39.github.io/ecma262/#sec-ecmascript-language-types-string-type\">Section 6.1.4</a> of the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_create_string_latin1"
},
{
"textRaw": "napi_create_string_utf16",
"name": "napi_create_string_utf16",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_string_utf16(napi_env env,\n const char16_t* str,\n size_t length,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] str</code>: Character buffer representing a UTF16-LE-encoded string.</li>\n<li><code>[in] length</code>: The length of the string in two-byte code units, or\n<code>NAPI_AUTO_LENGTH</code> if it is null-terminated.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>String</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API creates a JavaScript <code>String</code> object from a UTF16-LE-encoded C string.\nThe native string is copied.</p>\n<p>The JavaScript <code>String</code> type is described in\n<a href=\"https://tc39.github.io/ecma262/#sec-ecmascript-language-types-string-type\">Section 6.1.4</a> of the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_create_string_utf16"
},
{
"textRaw": "napi_create_string_utf8",
"name": "napi_create_string_utf8",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_string_utf8(napi_env env,\n const char* str,\n size_t length,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] str</code>: Character buffer representing a UTF8-encoded string.</li>\n<li><code>[in] length</code>: The length of the string in bytes, or <code>NAPI_AUTO_LENGTH</code>\nif it is null-terminated.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing a JavaScript <code>String</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API creates a JavaScript <code>String</code> object from a UTF8-encoded C string.\nThe native string is copied.</p>\n<p>The JavaScript <code>String</code> type is described in\n<a href=\"https://tc39.github.io/ecma262/#sec-ecmascript-language-types-string-type\">Section 6.1.4</a> of the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_create_string_utf8"
}
],
"type": "module",
"displayName": "Functions to convert from C types to N-API"
},
{
"textRaw": "Functions to convert from N-API to C types",
"name": "functions_to_convert_from_n-api_to_c_types",
"modules": [
{
"textRaw": "napi_get_array_length",
"name": "napi_get_array_length",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_array_length(napi_env env,\n napi_value value,\n uint32_t* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: <code>napi_value</code> representing the JavaScript <code>Array</code> whose length is\nbeing queried.</li>\n<li><code>[out] result</code>: <code>uint32</code> representing length of the array.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns the length of an array.</p>\n<p><code>Array</code> length is described in\n<a href=\"https://tc39.github.io/ecma262/#sec-properties-of-array-instances-length\">Section 22.1.4.1</a>\nof the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_get_array_length"
},
{
"textRaw": "napi_get_arraybuffer_info",
"name": "napi_get_arraybuffer_info",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_arraybuffer_info(napi_env env,\n napi_value arraybuffer,\n void** data,\n size_t* byte_length)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] arraybuffer</code>: <code>napi_value</code> representing the <code>ArrayBuffer</code> being queried.</li>\n<li><code>[out] data</code>: The underlying data buffer of the <code>ArrayBuffer</code>.</li>\n<li><code>[out] byte_length</code>: Length in bytes of the underlying data buffer.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API is used to retrieve the underlying data buffer of an <code>ArrayBuffer</code> and\nits length.</p>\n<p><em>WARNING</em>: Use caution while using this API. The lifetime of the underlying data\nbuffer is managed by the <code>ArrayBuffer</code> even after it&#39;s returned. A\npossible safe way to use this API is in conjunction with\n<a href=\"#n_api_napi_create_reference\"><code>napi_create_reference</code></a>, which can be used to guarantee control over the\nlifetime of the <code>ArrayBuffer</code>. It&#39;s also safe to use the returned data buffer\nwithin the same callback as long as there are no calls to other APIs that might\ntrigger a GC.</p>\n",
"type": "module",
"displayName": "napi_get_arraybuffer_info"
},
{
"textRaw": "napi_get_buffer_info",
"name": "napi_get_buffer_info",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_buffer_info(napi_env env,\n napi_value value,\n void** data,\n size_t* length)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: <code>napi_value</code> representing the <code>node::Buffer</code> being queried.</li>\n<li><code>[out] data</code>: The underlying data buffer of the <code>node::Buffer</code>.</li>\n<li><code>[out] length</code>: Length in bytes of the underlying data buffer.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API is used to retrieve the underlying data buffer of a <code>node::Buffer</code>\nand it&#39;s length.</p>\n<p><em>Warning</em>: Use caution while using this API since the underlying data buffer&#39;s\nlifetime is not guaranteed if it&#39;s managed by the VM.</p>\n",
"type": "module",
"displayName": "napi_get_buffer_info"
},
{
"textRaw": "napi_get_prototype",
"name": "napi_get_prototype",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_prototype(napi_env env,\n napi_value object,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] object</code>: <code>napi_value</code> representing JavaScript <code>Object</code> whose prototype\nto return. This returns the equivalent of <code>Object.getPrototypeOf</code> (which is\nnot the same as the function&#39;s <code>prototype</code> property).</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing prototype of the given object.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n",
"type": "module",
"displayName": "napi_get_prototype"
},
{
"textRaw": "napi_get_typedarray_info",
"name": "napi_get_typedarray_info",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_typedarray_info(napi_env env,\n napi_value typedarray,\n napi_typedarray_type* type,\n size_t* length,\n void** data,\n napi_value* arraybuffer,\n size_t* byte_offset)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] typedarray</code>: <code>napi_value</code> representing the <code>TypedArray</code> whose\nproperties to query.</li>\n<li><code>[out] type</code>: Scalar datatype of the elements within the <code>TypedArray</code>.</li>\n<li><code>[out] length</code>: The number of elements in the <code>TypedArray</code>.</li>\n<li><code>[out] data</code>: The data buffer underlying the <code>TypedArray</code> adjusted by\nthe <code>byte_offset</code> value so that it points to the first element in the\n<code>TypedArray</code>.</li>\n<li><code>[out] arraybuffer</code>: The <code>ArrayBuffer</code> underlying the <code>TypedArray</code>.</li>\n<li><code>[out] byte_offset</code>: The byte offset within the underlying native array\nat which the first element of the arrays is located. The value for the data\nparameter has already been adjusted so that data points to the first element\nin the array. Therefore, the first byte of the native array would be at\ndata - <code>byte_offset</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns various properties of a typed array.</p>\n<p><em>Warning</em>: Use caution while using this API since the underlying data buffer\nis managed by the VM.</p>\n",
"type": "module",
"displayName": "napi_get_typedarray_info"
},
{
"textRaw": "napi_get_dataview_info",
"name": "napi_get_dataview_info",
"meta": {
"added": [
"v8.3.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_dataview_info(napi_env env,\n napi_value dataview,\n size_t* byte_length,\n void** data,\n napi_value* arraybuffer,\n size_t* byte_offset)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] dataview</code>: <code>napi_value</code> representing the <code>DataView</code> whose\nproperties to query.</li>\n<li><code>[out] byte_length</code>: <code>Number</code> of bytes in the <code>DataView</code>.</li>\n<li><code>[out] data</code>: The data buffer underlying the <code>DataView</code>.</li>\n<li><code>[out] arraybuffer</code>: <code>ArrayBuffer</code> underlying the <code>DataView</code>.</li>\n<li><code>[out] byte_offset</code>: The byte offset within the data buffer from which\nto start projecting the <code>DataView</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns various properties of a <code>DataView</code>.</p>\n",
"type": "module",
"displayName": "napi_get_dataview_info"
},
{
"textRaw": "napi_get_value_bool",
"name": "napi_get_value_bool",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_value_bool(napi_env env, napi_value value, bool* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>Boolean</code>.</li>\n<li><code>[out] result</code>: C boolean primitive equivalent of the given JavaScript\n<code>Boolean</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded. If a non-boolean <code>napi_value</code> is\npassed in it returns <code>napi_boolean_expected</code>.</p>\n<p>This API returns the C boolean primitive equivalent of the given JavaScript\n<code>Boolean</code>.</p>\n",
"type": "module",
"displayName": "napi_get_value_bool"
},
{
"textRaw": "napi_get_value_double",
"name": "napi_get_value_double",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_value_double(napi_env env,\n napi_value value,\n double* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>Number</code>.</li>\n<li><code>[out] result</code>: C double primitive equivalent of the given JavaScript\n<code>Number</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded. If a non-number <code>napi_value</code> is passed\nin it returns <code>napi_number_expected</code>.</p>\n<p>This API returns the C double primitive equivalent of the given JavaScript\n<code>Number</code>.</p>\n",
"type": "module",
"displayName": "napi_get_value_double"
},
{
"textRaw": "napi_get_value_external",
"name": "napi_get_value_external",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_value_external(napi_env env,\n napi_value value,\n void** result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: <code>napi_value</code> representing JavaScript external value.</li>\n<li><code>[out] result</code>: Pointer to the data wrapped by the JavaScript external value.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded. If a non-external <code>napi_value</code> is\npassed in it returns <code>napi_invalid_arg</code>.</p>\n<p>This API retrieves the external data pointer that was previously passed to\n<code>napi_create_external()</code>.</p>\n",
"type": "module",
"displayName": "napi_get_value_external"
},
{
"textRaw": "napi_get_value_int32",
"name": "napi_get_value_int32",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_value_int32(napi_env env,\n napi_value value,\n int32_t* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>Number</code>.</li>\n<li><code>[out] result</code>: C <code>int32</code> primitive equivalent of the given JavaScript\n<code>Number</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded. If a non-number <code>napi_value</code>\nis passed in <code>napi_number_expected</code>.</p>\n<p>This API returns the C <code>int32</code> primitive equivalent\nof the given JavaScript <code>Number</code>.</p>\n<p>If the number exceeds the range of the 32 bit integer, then the result is\ntruncated to the equivalent of the bottom 32 bits. This can result in a large\npositive number becoming a negative number if the value is &gt; 2^31 -1.</p>\n<p>Non-finite number values (<code>NaN</code>, <code>+Infinity</code>, or <code>-Infinity</code>) set the\nresult to zero.</p>\n",
"type": "module",
"displayName": "napi_get_value_int32"
},
{
"textRaw": "napi_get_value_int64",
"name": "napi_get_value_int64",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_value_int64(napi_env env,\n napi_value value,\n int64_t* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>Number</code>.</li>\n<li><code>[out] result</code>: C <code>int64</code> primitive equivalent of the given JavaScript\n<code>Number</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded. If a non-number <code>napi_value</code>\nis passed in it returns <code>napi_number_expected</code>.</p>\n<p>This API returns the C <code>int64</code> primitive equivalent of the given JavaScript\n<code>Number</code>.</p>\n<p><code>Number</code> values outside the range of\n<a href=\"https://tc39.github.io/ecma262/#sec-number.min_safe_integer\"><code>Number.MIN_SAFE_INTEGER</code></a>\n-(2^53 - 1) -\n<a href=\"https://tc39.github.io/ecma262/#sec-number.max_safe_integer\"><code>Number.MAX_SAFE_INTEGER</code></a>\n(2^53 - 1) will lose precision.</p>\n<p>Non-finite number values (<code>NaN</code>, <code>+Infinity</code>, or <code>-Infinity</code>) set the\nresult to zero.</p>\n",
"type": "module",
"displayName": "napi_get_value_int64"
},
{
"textRaw": "napi_get_value_string_latin1",
"name": "napi_get_value_string_latin1",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_value_string_latin1(napi_env env,\n napi_value value,\n char* buf,\n size_t bufsize,\n size_t* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: <code>napi_value</code> representing JavaScript string.</li>\n<li><code>[in] buf</code>: Buffer to write the ISO-8859-1-encoded string into. If NULL is\npassed in, the length of the string (in bytes) is returned.</li>\n<li><code>[in] bufsize</code>: Size of the destination buffer. When this value is\ninsufficient, the returned string will be truncated.</li>\n<li><code>[out] result</code>: Number of bytes copied into the buffer, excluding the null\nterminator.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded. If a non-<code>String</code> <code>napi_value</code>\nis passed in it returns <code>napi_string_expected</code>.</p>\n<p>This API returns the ISO-8859-1-encoded string corresponding the value passed\nin.</p>\n",
"type": "module",
"displayName": "napi_get_value_string_latin1"
},
{
"textRaw": "napi_get_value_string_utf8",
"name": "napi_get_value_string_utf8",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_value_string_utf8(napi_env env,\n napi_value value,\n char* buf,\n size_t bufsize,\n size_t* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: <code>napi_value</code> representing JavaScript string.</li>\n<li><code>[in] buf</code>: Buffer to write the UTF8-encoded string into. If NULL is passed\nin, the length of the string (in bytes) is returned.</li>\n<li><code>[in] bufsize</code>: Size of the destination buffer. When this value is\ninsufficient, the returned string will be truncated.</li>\n<li><code>[out] result</code>: Number of bytes copied into the buffer, excluding the null\nterminator.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded. If a non-<code>String</code> <code>napi_value</code>\nis passed in it returns <code>napi_string_expected</code>.</p>\n<p>This API returns the UTF8-encoded string corresponding the value passed in.</p>\n",
"type": "module",
"displayName": "napi_get_value_string_utf8"
},
{
"textRaw": "napi_get_value_string_utf16",
"name": "napi_get_value_string_utf16",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_value_string_utf16(napi_env env,\n napi_value value,\n char16_t* buf,\n size_t bufsize,\n size_t* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: <code>napi_value</code> representing JavaScript string.</li>\n<li><code>[in] buf</code>: Buffer to write the UTF16-LE-encoded string into. If NULL is\npassed in, the length of the string (in 2-byte code units) is returned.</li>\n<li><code>[in] bufsize</code>: Size of the destination buffer. When this value is\ninsufficient, the returned string will be truncated.</li>\n<li><code>[out] result</code>: Number of 2-byte code units copied into the buffer, excluding\nthe null terminator.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded. If a non-<code>String</code> <code>napi_value</code>\nis passed in it returns <code>napi_string_expected</code>.</p>\n<p>This API returns the UTF16-encoded string corresponding the value passed in.</p>\n",
"type": "module",
"displayName": "napi_get_value_string_utf16"
},
{
"textRaw": "napi_get_value_uint32",
"name": "napi_get_value_uint32",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_value_uint32(napi_env env,\n napi_value value,\n uint32_t* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: <code>napi_value</code> representing JavaScript <code>Number</code>.</li>\n<li><code>[out] result</code>: C primitive equivalent of the given <code>napi_value</code> as a\n<code>uint32_t</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded. If a non-number <code>napi_value</code>\nis passed in it returns <code>napi_number_expected</code>.</p>\n<p>This API returns the C primitive equivalent of the given <code>napi_value</code> as a\n<code>uint32_t</code>.</p>\n",
"type": "module",
"displayName": "napi_get_value_uint32"
}
],
"type": "module",
"displayName": "Functions to convert from N-API to C types"
},
{
"textRaw": "Functions to get global instances",
"name": "functions_to_get_global_instances",
"modules": [
{
"textRaw": "napi_get_boolean",
"name": "napi_get_boolean",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_boolean(napi_env env, bool value, napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: The value of the boolean to retrieve.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing JavaScript <code>Boolean</code> singleton to\nretrieve.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API is used to return the JavaScript singleton object that is used to\nrepresent the given boolean value.</p>\n",
"type": "module",
"displayName": "napi_get_boolean"
},
{
"textRaw": "napi_get_global",
"name": "napi_get_global",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_global(napi_env env, napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing JavaScript <code>global</code> object.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns the <code>global</code> object.</p>\n",
"type": "module",
"displayName": "napi_get_global"
},
{
"textRaw": "napi_get_null",
"name": "napi_get_null",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_null(napi_env env, napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing JavaScript <code>null</code> object.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns the <code>null</code> object.</p>\n",
"type": "module",
"displayName": "napi_get_null"
},
{
"textRaw": "napi_get_undefined",
"name": "napi_get_undefined",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_undefined(napi_env env, napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing JavaScript Undefined value.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns the Undefined object.</p>\n",
"type": "module",
"displayName": "napi_get_undefined"
}
],
"type": "module",
"displayName": "Functions to get global instances"
}
],
"type": "misc",
"displayName": "Working with JavaScript Values"
},
{
"textRaw": "Working with JavaScript Values - Abstract Operations",
"name": "working_with_javascript_values_-_abstract_operations",
"desc": "<p>N-API exposes a set of APIs to perform some abstract operations on JavaScript\nvalues. Some of these operations are documented under\n<a href=\"https://tc39.github.io/ecma262/#sec-abstract-operations\">Section 7</a>\nof the <a href=\"https://tc39.github.io/ecma262/\">ECMAScript Language Specification</a>.</p>\n<p>These APIs support doing one of the following:</p>\n<ol>\n<li>Coerce JavaScript values to specific JavaScript types (such as <code>Number</code> or\n<code>String</code>).</li>\n<li>Check the type of a JavaScript value.</li>\n<li>Check for equality between two JavaScript values.</li>\n</ol>\n",
"modules": [
{
"textRaw": "napi_coerce_to_bool",
"name": "napi_coerce_to_bool",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_coerce_to_bool(napi_env env,\n napi_value value,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: The JavaScript value to coerce.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing the coerced JavaScript <code>Boolean</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API implements the abstract operation <code>ToBoolean()</code> as defined in\n<a href=\"https://tc39.github.io/ecma262/#sec-toboolean\">Section 7.1.2</a>\nof the ECMAScript Language Specification.\nThis API can be re-entrant if getters are defined on the passed-in <code>Object</code>.</p>\n",
"type": "module",
"displayName": "napi_coerce_to_bool"
},
{
"textRaw": "napi_coerce_to_number",
"name": "napi_coerce_to_number",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_coerce_to_number(napi_env env,\n napi_value value,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: The JavaScript value to coerce.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing the coerced JavaScript <code>Number</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API implements the abstract operation <code>ToNumber()</code> as defined in\n<a href=\"https://tc39.github.io/ecma262/#sec-tonumber\">Section 7.1.3</a>\nof the ECMAScript Language Specification.\nThis API can be re-entrant if getters are defined on the passed-in <code>Object</code>.</p>\n",
"type": "module",
"displayName": "napi_coerce_to_number"
},
{
"textRaw": "napi_coerce_to_object",
"name": "napi_coerce_to_object",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_coerce_to_object(napi_env env,\n napi_value value,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: The JavaScript value to coerce.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing the coerced JavaScript <code>Object</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API implements the abstract operation <code>ToObject()</code> as defined in\n<a href=\"https://tc39.github.io/ecma262/#sec-toobject\">Section 7.1.13</a>\nof the ECMAScript Language Specification.\nThis API can be re-entrant if getters are defined on the passed-in <code>Object</code>.</p>\n",
"type": "module",
"displayName": "napi_coerce_to_object"
},
{
"textRaw": "napi_coerce_to_string",
"name": "napi_coerce_to_string",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_coerce_to_string(napi_env env,\n napi_value value,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: The JavaScript value to coerce.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing the coerced JavaScript <code>String</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API implements the abstract operation <code>ToString()</code> as defined in\n<a href=\"https://tc39.github.io/ecma262/#sec-tostring\">Section 7.1.13</a>\nof the ECMAScript Language Specification.\nThis API can be re-entrant if getters are defined on the passed-in <code>Object</code>.</p>\n",
"type": "module",
"displayName": "napi_coerce_to_string"
},
{
"textRaw": "napi_typeof",
"name": "napi_typeof",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_typeof(napi_env env, napi_value value, napi_valuetype* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: The JavaScript value whose type to query.</li>\n<li><code>[out] result</code>: The type of the JavaScript value.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<ul>\n<li><code>napi_invalid_arg</code> if the type of <code>value</code> is not a known ECMAScript type and\n<code>value</code> is not an External value.</li>\n</ul>\n<p>This API represents behavior similar to invoking the <code>typeof</code> Operator on\nthe object as defined in <a href=\"https://tc39.github.io/ecma262/#sec-typeof-operator\">Section 12.5.5</a> of the ECMAScript Language\nSpecification. However, it has support for detecting an External value.\nIf <code>value</code> has a type that is invalid, an error is returned.</p>\n",
"type": "module",
"displayName": "napi_typeof"
},
{
"textRaw": "napi_instanceof",
"name": "napi_instanceof",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_instanceof(napi_env env,\n napi_value object,\n napi_value constructor,\n bool* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] object</code>: The JavaScript value to check.</li>\n<li><code>[in] constructor</code>: The JavaScript function object of the constructor\nfunction to check against.</li>\n<li><code>[out] result</code>: Boolean that is set to true if <code>object instanceof constructor</code>\nis true.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API represents invoking the <code>instanceof</code> Operator on the object as\ndefined in\n<a href=\"https://tc39.github.io/ecma262/#sec-instanceofoperator\">Section 12.10.4</a>\nof the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_instanceof"
},
{
"textRaw": "napi_is_array",
"name": "napi_is_array",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_is_array(napi_env env, napi_value value, bool* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: The JavaScript value to check.</li>\n<li><code>[out] result</code>: Whether the given object is an array.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API represents invoking the <code>IsArray</code> operation on the object\nas defined in <a href=\"https://tc39.github.io/ecma262/#sec-isarray\">Section 7.2.2</a>\nof the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_is_array"
},
{
"textRaw": "napi_is_arraybuffer",
"name": "napi_is_arraybuffer",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_is_arraybuffer(napi_env env, napi_value value, bool* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: The JavaScript value to check.</li>\n<li><code>[out] result</code>: Whether the given object is an <code>ArrayBuffer</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API checks if the <code>Object</code> passed in is an array buffer.</p>\n",
"type": "module",
"displayName": "napi_is_arraybuffer"
},
{
"textRaw": "napi_is_buffer",
"name": "napi_is_buffer",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_is_buffer(napi_env env, napi_value value, bool* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: The JavaScript value to check.</li>\n<li><code>[out] result</code>: Whether the given <code>napi_value</code> represents a <code>node::Buffer</code>\nobject.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API checks if the <code>Object</code> passed in is a buffer.</p>\n",
"type": "module",
"displayName": "napi_is_buffer"
},
{
"textRaw": "napi_is_error",
"name": "napi_is_error",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_is_error(napi_env env, napi_value value, bool* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: The JavaScript value to check.</li>\n<li><code>[out] result</code>: Whether the given <code>napi_value</code> represents an <code>Error</code> object.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API checks if the <code>Object</code> passed in is an <code>Error</code>.</p>\n",
"type": "module",
"displayName": "napi_is_error"
},
{
"textRaw": "napi_is_typedarray",
"name": "napi_is_typedarray",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_is_typedarray(napi_env env, napi_value value, bool* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: The JavaScript value to check.</li>\n<li><code>[out] result</code>: Whether the given <code>napi_value</code> represents a <code>TypedArray</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API checks if the <code>Object</code> passed in is a typed array.</p>\n",
"type": "module",
"displayName": "napi_is_typedarray"
},
{
"textRaw": "napi_is_dataview",
"name": "napi_is_dataview",
"meta": {
"added": [
"v8.3.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_is_dataview(napi_env env, napi_value value, bool* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] value</code>: The JavaScript value to check.</li>\n<li><code>[out] result</code>: Whether the given <code>napi_value</code> represents a <code>DataView</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API checks if the <code>Object</code> passed in is a <code>DataView</code>.</p>\n",
"type": "module",
"displayName": "napi_is_dataview"
},
{
"textRaw": "napi_strict_equals",
"name": "napi_strict_equals",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_strict_equals(napi_env env,\n napi_value lhs,\n napi_value rhs,\n bool* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] lhs</code>: The JavaScript value to check.</li>\n<li><code>[in] rhs</code>: The JavaScript value to check against.</li>\n<li><code>[out] result</code>: Whether the two <code>napi_value</code> objects are equal.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API represents the invocation of the Strict Equality algorithm as\ndefined in\n<a href=\"https://tc39.github.io/ecma262/#sec-strict-equality-comparison\">Section 7.2.14</a>\nof the ECMAScript Language Specification.</p>\n",
"type": "module",
"displayName": "napi_strict_equals"
}
],
"type": "misc",
"displayName": "Working with JavaScript Values - Abstract Operations"
},
{
"textRaw": "Working with JavaScript Properties",
"name": "working_with_javascript_properties",
"desc": "<p>N-API exposes a set of APIs to get and set properties on JavaScript\nobjects. Some of these types are documented under\n<a href=\"https://tc39.github.io/ecma262/#sec-operations-on-objects\">Section 7</a> of the\n<a href=\"https://tc39.github.io/ecma262/\">ECMAScript Language Specification</a>.</p>\n<p>Properties in JavaScript are represented as a tuple of a key and a value.\nFundamentally, all property keys in N-API can be represented in one of the\nfollowing forms:</p>\n<ul>\n<li>Named: a simple UTF8-encoded string</li>\n<li>Integer-Indexed: an index value represented by <code>uint32_t</code></li>\n<li>JavaScript value: these are represented in N-API by <code>napi_value</code>. This can\nbe a <code>napi_value</code> representing a <code>String</code>, <code>Number</code>, or <code>Symbol</code>.</li>\n</ul>\n<p>N-API values are represented by the type <code>napi_value</code>.\nAny N-API call that requires a JavaScript value takes in a <code>napi_value</code>.\nHowever, it&#39;s the caller&#39;s responsibility to make sure that the\n<code>napi_value</code> in question is of the JavaScript type expected by the API.</p>\n<p>The APIs documented in this section provide a simple interface to\nget and set properties on arbitrary JavaScript objects represented by\n<code>napi_value</code>.</p>\n<p>For instance, consider the following JavaScript code snippet:</p>\n<pre><code class=\"lang-js\">const obj = {};\nobj.myProp = 123;\n</code></pre>\n<p>The equivalent can be done using N-API values with the following snippet:</p>\n<pre><code class=\"lang-C\">napi_status status = napi_generic_failure;\n\n// const obj = {}\nnapi_value obj, value;\nstatus = napi_create_object(env, &amp;obj);\nif (status != napi_ok) return status;\n\n// Create a napi_value for 123\nstatus = napi_create_int32(env, 123, &amp;value);\nif (status != napi_ok) return status;\n\n// obj.myProp = 123\nstatus = napi_set_named_property(env, obj, &quot;myProp&quot;, value);\nif (status != napi_ok) return status;\n</code></pre>\n<p>Indexed properties can be set in a similar manner. Consider the following\nJavaScript snippet:</p>\n<pre><code class=\"lang-js\">const arr = [];\narr[123] = &#39;hello&#39;;\n</code></pre>\n<p>The equivalent can be done using N-API values with the following snippet:</p>\n<pre><code class=\"lang-C\">napi_status status = napi_generic_failure;\n\n// const arr = [];\nnapi_value arr, value;\nstatus = napi_create_array(env, &amp;arr);\nif (status != napi_ok) return status;\n\n// Create a napi_value for &#39;hello&#39;\nstatus = napi_create_string_utf8(env, &quot;hello&quot;, NAPI_AUTO_LENGTH, &amp;value);\nif (status != napi_ok) return status;\n\n// arr[123] = &#39;hello&#39;;\nstatus = napi_set_element(env, arr, 123, value);\nif (status != napi_ok) return status;\n</code></pre>\n<p>Properties can be retrieved using the APIs described in this section.\nConsider the following JavaScript snippet:</p>\n<pre><code class=\"lang-js\">const arr = [];\nconst value = arr[123];\n</code></pre>\n<p>The following is the approximate equivalent of the N-API counterpart:</p>\n<pre><code class=\"lang-C\">napi_status status = napi_generic_failure;\n\n// const arr = []\nnapi_value arr, value;\nstatus = napi_create_array(env, &amp;arr);\nif (status != napi_ok) return status;\n\n// const value = arr[123]\nstatus = napi_get_element(env, arr, 123, &amp;value);\nif (status != napi_ok) return status;\n</code></pre>\n<p>Finally, multiple properties can also be defined on an object for performance\nreasons. Consider the following JavaScript:</p>\n<pre><code class=\"lang-js\">const obj = {};\nObject.defineProperties(obj, {\n &#39;foo&#39;: { value: 123, writable: true, configurable: true, enumerable: true },\n &#39;bar&#39;: { value: 456, writable: true, configurable: true, enumerable: true }\n});\n</code></pre>\n<p>The following is the approximate equivalent of the N-API counterpart:</p>\n<pre><code class=\"lang-C\">napi_status status = napi_status_generic_failure;\n\n// const obj = {};\nnapi_value obj;\nstatus = napi_create_object(env, &amp;obj);\nif (status != napi_ok) return status;\n\n// Create napi_values for 123 and 456\nnapi_value fooValue, barValue;\nstatus = napi_create_int32(env, 123, &amp;fooValue);\nif (status != napi_ok) return status;\nstatus = napi_create_int32(env, 456, &amp;barValue);\nif (status != napi_ok) return status;\n\n// Set the properties\nnapi_property_descriptor descriptors[] = {\n { &quot;foo&quot;, NULL, NULL, NULL, NULL, fooValue, napi_default, NULL },\n { &quot;bar&quot;, NULL, NULL, NULL, NULL, barValue, napi_default, NULL }\n}\nstatus = napi_define_properties(env,\n obj,\n sizeof(descriptors) / sizeof(descriptors[0]),\n descriptors);\nif (status != napi_ok) return status;\n</code></pre>\n",
"modules": [
{
"textRaw": "Structures",
"name": "structures",
"modules": [
{
"textRaw": "napi_property_attributes",
"name": "napi_property_attributes",
"desc": "<pre><code class=\"lang-C\">typedef enum {\n napi_default = 0,\n napi_writable = 1 &lt;&lt; 0,\n napi_enumerable = 1 &lt;&lt; 1,\n napi_configurable = 1 &lt;&lt; 2,\n\n // Used with napi_define_class to distinguish static properties\n // from instance properties. Ignored by napi_define_properties.\n napi_static = 1 &lt;&lt; 10,\n} napi_property_attributes;\n</code></pre>\n<p><code>napi_property_attributes</code> are flags used to control the behavior of properties\nset on a JavaScript object. Other than <code>napi_static</code> they correspond to the\nattributes listed in <a href=\"https://tc39.github.io/ecma262/#table-2\">Section 6.1.7.1</a>\nof the <a href=\"https://tc39.github.io/ecma262/\">ECMAScript Language Specification</a>.\nThey can be one or more of the following bitflags:</p>\n<ul>\n<li><code>napi_default</code> - Used to indicate that no explicit attributes are set on the\ngiven property. By default, a property is read only, not enumerable and not\nconfigurable.</li>\n<li><code>napi_writable</code> - Used to indicate that a given property is writable.</li>\n<li><code>napi_enumerable</code> - Used to indicate that a given property is enumerable.</li>\n<li><code>napi_configurable</code> - Used to indicate that a given property is configurable,\nas defined in <a href=\"https://tc39.github.io/ecma262/#table-2\">Section 6.1.7.1</a> of the <a href=\"https://tc39.github.io/ecma262/\">ECMAScript Language Specification</a>.</li>\n<li><code>napi_static</code> - Used to indicate that the property will be defined as\na static property on a class as opposed to an instance property, which is the\ndefault. This is used only by <a href=\"#n_api_napi_define_class\"><code>napi_define_class</code></a>. It is ignored by\n<code>napi_define_properties</code>.</li>\n</ul>\n",
"type": "module",
"displayName": "napi_property_attributes"
},
{
"textRaw": "napi_property_descriptor",
"name": "napi_property_descriptor",
"desc": "<pre><code class=\"lang-C\">typedef struct {\n // One of utf8name or name should be NULL.\n const char* utf8name;\n napi_value name;\n\n napi_callback method;\n napi_callback getter;\n napi_callback setter;\n napi_value value;\n\n napi_property_attributes attributes;\n void* data;\n} napi_property_descriptor;\n</code></pre>\n<ul>\n<li><code>utf8name</code>: Optional <code>String</code> describing the key for the property,\nencoded as UTF8. One of <code>utf8name</code> or <code>name</code> must be provided for the\nproperty.</li>\n<li><code>name</code>: Optional <code>napi_value</code> that points to a JavaScript string or symbol\nto be used as the key for the property. One of <code>utf8name</code> or <code>name</code> must\nbe provided for the property.</li>\n<li><code>value</code>: The value that&#39;s retrieved by a get access of the property if the\nproperty is a data property. If this is passed in, set <code>getter</code>, <code>setter</code>,\n<code>method</code> and <code>data</code> to <code>NULL</code> (since these members won&#39;t be used).</li>\n<li><code>getter</code>: A function to call when a get access of the property is performed.\nIf this is passed in, set <code>value</code> and <code>method</code> to <code>NULL</code> (since these members\nwon&#39;t be used). The given function is called implicitly by the runtime when the\nproperty is accessed from JavaScript code (or if a get on the property is\nperformed using a N-API call).</li>\n<li><code>setter</code>: A function to call when a set access of the property is performed.\nIf this is passed in, set <code>value</code> and <code>method</code> to <code>NULL</code> (since these members\nwon&#39;t be used). The given function is called implicitly by the runtime when the\nproperty is set from JavaScript code (or if a set on the property is\nperformed using a N-API call).</li>\n<li><code>method</code>: Set this to make the property descriptor object&#39;s <code>value</code>\nproperty to be a JavaScript function represented by <code>method</code>. If this is\npassed in, set <code>value</code>, <code>getter</code> and <code>setter</code> to <code>NULL</code> (since these members\nwon&#39;t be used).</li>\n<li><code>attributes</code>: The attributes associated with the particular property.\nSee <a href=\"#n_api_napi_property_attributes\"><code>napi_property_attributes</code></a>.</li>\n<li><code>data</code>: The callback data passed into <code>method</code>, <code>getter</code> and <code>setter</code> if\nthis function is invoked.</li>\n</ul>\n",
"type": "module",
"displayName": "napi_property_descriptor"
}
],
"type": "module",
"displayName": "Structures"
},
{
"textRaw": "Functions",
"name": "functions",
"modules": [
{
"textRaw": "napi_get_property_names",
"name": "napi_get_property_names",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_property_names(napi_env env,\n napi_value object,\n napi_value* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the N-API call is invoked under.</li>\n<li><code>[in] object</code>: The object from which to retrieve the properties.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing an array of JavaScript values\nthat represent the property names of the object. The API can be used to\niterate over <code>result</code> using <a href=\"#n_api_napi_get_array_length\"><code>napi_get_array_length</code></a>\nand <a href=\"#n_api_napi_get_element\"><code>napi_get_element</code></a>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns the names of the enumerable properties of <code>object</code> as an array\nof strings. The properties of <code>object</code> whose key is a symbol will not be\nincluded.</p>\n",
"type": "module",
"displayName": "napi_get_property_names"
},
{
"textRaw": "napi_set_property",
"name": "napi_set_property",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_set_property(napi_env env,\n napi_value object,\n napi_value key,\n napi_value value);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the N-API call is invoked under.</li>\n<li><code>[in] object</code>: The object on which to set the property.</li>\n<li><code>[in] key</code>: The name of the property to set.</li>\n<li><code>[in] value</code>: The property value.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API set a property on the <code>Object</code> passed in.</p>\n",
"type": "module",
"displayName": "napi_set_property"
},
{
"textRaw": "napi_get_property",
"name": "napi_get_property",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_property(napi_env env,\n napi_value object,\n napi_value key,\n napi_value* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the N-API call is invoked under.</li>\n<li><code>[in] object</code>: The object from which to retrieve the property.</li>\n<li><code>[in] key</code>: The name of the property to retrieve.</li>\n<li><code>[out] result</code>: The value of the property.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API gets the requested property from the <code>Object</code> passed in.</p>\n",
"type": "module",
"displayName": "napi_get_property"
},
{
"textRaw": "napi_has_property",
"name": "napi_has_property",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_has_property(napi_env env,\n napi_value object,\n napi_value key,\n bool* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the N-API call is invoked under.</li>\n<li><code>[in] object</code>: The object to query.</li>\n<li><code>[in] key</code>: The name of the property whose existence to check.</li>\n<li><code>[out] result</code>: Whether the property exists on the object or not.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API checks if the <code>Object</code> passed in has the named property.</p>\n",
"type": "module",
"displayName": "napi_has_property"
},
{
"textRaw": "napi_delete_property",
"name": "napi_delete_property",
"meta": {
"added": [
"v8.2.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_delete_property(napi_env env,\n napi_value object,\n napi_value key,\n bool* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the N-API call is invoked under.</li>\n<li><code>[in] object</code>: The object to query.</li>\n<li><code>[in] key</code>: The name of the property to delete.</li>\n<li><code>[out] result</code>: Whether the property deletion succeeded or not. <code>result</code> can\noptionally be ignored by passing <code>NULL</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API attempts to delete the <code>key</code> own property from <code>object</code>.</p>\n",
"type": "module",
"displayName": "napi_delete_property"
},
{
"textRaw": "napi_has_own_property",
"name": "napi_has_own_property",
"meta": {
"added": [
"v8.2.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_has_own_property(napi_env env,\n napi_value object,\n napi_value key,\n bool* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the N-API call is invoked under.</li>\n<li><code>[in] object</code>: The object to query.</li>\n<li><code>[in] key</code>: The name of the own property whose existence to check.</li>\n<li><code>[out] result</code>: Whether the own property exists on the object or not.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API checks if the <code>Object</code> passed in has the named own property. <code>key</code> must\nbe a string or a <code>Symbol</code>, or an error will be thrown. N-API will not perform\nany conversion between data types.</p>\n",
"type": "module",
"displayName": "napi_has_own_property"
},
{
"textRaw": "napi_set_named_property",
"name": "napi_set_named_property",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_set_named_property(napi_env env,\n napi_value object,\n const char* utf8Name,\n napi_value value);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the N-API call is invoked under.</li>\n<li><code>[in] object</code>: The object on which to set the property.</li>\n<li><code>[in] utf8Name</code>: The name of the property to set.</li>\n<li><code>[in] value</code>: The property value.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This method is equivalent to calling <a href=\"#n_api_napi_set_property\"><code>napi_set_property</code></a> with a <code>napi_value</code>\ncreated from the string passed in as <code>utf8Name</code>.</p>\n",
"type": "module",
"displayName": "napi_set_named_property"
},
{
"textRaw": "napi_get_named_property",
"name": "napi_get_named_property",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_named_property(napi_env env,\n napi_value object,\n const char* utf8Name,\n napi_value* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the N-API call is invoked under.</li>\n<li><code>[in] object</code>: The object from which to retrieve the property.</li>\n<li><code>[in] utf8Name</code>: The name of the property to get.</li>\n<li><code>[out] result</code>: The value of the property.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This method is equivalent to calling <a href=\"#n_api_napi_get_property\"><code>napi_get_property</code></a> with a <code>napi_value</code>\ncreated from the string passed in as <code>utf8Name</code>.</p>\n",
"type": "module",
"displayName": "napi_get_named_property"
},
{
"textRaw": "napi_has_named_property",
"name": "napi_has_named_property",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_has_named_property(napi_env env,\n napi_value object,\n const char* utf8Name,\n bool* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the N-API call is invoked under.</li>\n<li><code>[in] object</code>: The object to query.</li>\n<li><code>[in] utf8Name</code>: The name of the property whose existence to check.</li>\n<li><code>[out] result</code>: Whether the property exists on the object or not.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This method is equivalent to calling <a href=\"#n_api_napi_has_property\"><code>napi_has_property</code></a> with a <code>napi_value</code>\ncreated from the string passed in as <code>utf8Name</code>.</p>\n",
"type": "module",
"displayName": "napi_has_named_property"
},
{
"textRaw": "napi_set_element",
"name": "napi_set_element",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_set_element(napi_env env,\n napi_value object,\n uint32_t index,\n napi_value value);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the N-API call is invoked under.</li>\n<li><code>[in] object</code>: The object from which to set the properties.</li>\n<li><code>[in] index</code>: The index of the property to set.</li>\n<li><code>[in] value</code>: The property value.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API sets and element on the <code>Object</code> passed in.</p>\n",
"type": "module",
"displayName": "napi_set_element"
},
{
"textRaw": "napi_get_element",
"name": "napi_get_element",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_element(napi_env env,\n napi_value object,\n uint32_t index,\n napi_value* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the N-API call is invoked under.</li>\n<li><code>[in] object</code>: The object from which to retrieve the property.</li>\n<li><code>[in] index</code>: The index of the property to get.</li>\n<li><code>[out] result</code>: The value of the property.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API gets the element at the requested index.</p>\n",
"type": "module",
"displayName": "napi_get_element"
},
{
"textRaw": "napi_has_element",
"name": "napi_has_element",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_has_element(napi_env env,\n napi_value object,\n uint32_t index,\n bool* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the N-API call is invoked under.</li>\n<li><code>[in] object</code>: The object to query.</li>\n<li><code>[in] index</code>: The index of the property whose existence to check.</li>\n<li><code>[out] result</code>: Whether the property exists on the object or not.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns if the <code>Object</code> passed in has an element at the\nrequested index.</p>\n",
"type": "module",
"displayName": "napi_has_element"
},
{
"textRaw": "napi_delete_element",
"name": "napi_delete_element",
"meta": {
"added": [
"v8.2.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_delete_element(napi_env env,\n napi_value object,\n uint32_t index,\n bool* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the N-API call is invoked under.</li>\n<li><code>[in] object</code>: The object to query.</li>\n<li><code>[in] index</code>: The index of the property to delete.</li>\n<li><code>[out] result</code>: Whether the element deletion succeeded or not. <code>result</code> can\noptionally be ignored by passing <code>NULL</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API attempts to delete the specified <code>index</code> from <code>object</code>.</p>\n",
"type": "module",
"displayName": "napi_delete_element"
},
{
"textRaw": "napi_define_properties",
"name": "napi_define_properties",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_define_properties(napi_env env,\n napi_value object,\n size_t property_count,\n const napi_property_descriptor* properties);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the N-API call is invoked under.</li>\n<li><code>[in] object</code>: The object from which to retrieve the properties.</li>\n<li><code>[in] property_count</code>: The number of elements in the <code>properties</code> array.</li>\n<li><code>[in] properties</code>: The array of property descriptors.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This method allows the efficient definition of multiple properties on a given\nobject. The properties are defined using property descriptors (see\n<a href=\"#n_api_napi_property_descriptor\"><code>napi_property_descriptor</code></a>). Given an array of such property descriptors,\nthis API will set the properties on the object one at a time, as defined by\n<code>DefineOwnProperty()</code> (described in <a href=\"https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-defineownproperty-p-desc\">Section 9.1.6</a> of the ECMA262\nspecification).</p>\n",
"type": "module",
"displayName": "napi_define_properties"
}
],
"type": "module",
"displayName": "Functions"
}
],
"type": "misc",
"displayName": "Working with JavaScript Properties"
},
{
"textRaw": "Working with JavaScript Functions",
"name": "working_with_javascript_functions",
"desc": "<p>N-API provides a set of APIs that allow JavaScript code to\ncall back into native code. N-API APIs that support calling back\ninto native code take in a callback functions represented by\nthe <code>napi_callback</code> type. When the JavaScript VM calls back to\nnative code, the <code>napi_callback</code> function provided is invoked. The APIs\ndocumented in this section allow the callback function to do the\nfollowing:</p>\n<ul>\n<li>Get information about the context in which the callback was invoked.</li>\n<li>Get the arguments passed into the callback.</li>\n<li>Return a <code>napi_value</code> back from the callback.</li>\n</ul>\n<p>Additionally, N-API provides a set of functions which allow calling\nJavaScript functions from native code. One can either call a function\nlike a regular JavaScript function call, or as a constructor\nfunction.</p>\n",
"modules": [
{
"textRaw": "napi_call_function",
"name": "napi_call_function",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_call_function(napi_env env,\n napi_value recv,\n napi_value func,\n int argc,\n const napi_value* argv,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] recv</code>: The <code>this</code> object passed to the called function.</li>\n<li><code>[in] func</code>: <code>napi_value</code> representing the JavaScript function\nto be invoked.</li>\n<li><code>[in] argc</code>: The count of elements in the <code>argv</code> array.</li>\n<li><code>[in] argv</code>: Array of <code>napi_values</code> representing JavaScript values passed\nin as arguments to the function.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing the JavaScript object returned.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This method allows a JavaScript function object to be called from a native\nadd-on. This is the primary mechanism of calling back <em>from</em> the add-on&#39;s\nnative code <em>into</em> JavaScript. For the special case of calling into JavaScript\nafter an async operation, see <a href=\"#n_api_napi_make_callback\"><code>napi_make_callback</code></a>.</p>\n<p>A sample use case might look as follows. Consider the following JavaScript\nsnippet:</p>\n<pre><code class=\"lang-js\">function AddTwo(num) {\n return num + 2;\n}\n</code></pre>\n<p>Then, the above function can be invoked from a native add-on using the\nfollowing code:</p>\n<pre><code class=\"lang-C\">// Get the function named &quot;AddTwo&quot; on the global object\nnapi_value global, add_two, arg;\nnapi_status status = napi_get_global(env, &amp;global);\nif (status != napi_ok) return;\n\nstatus = napi_get_named_property(env, global, &quot;AddTwo&quot;, &amp;add_two);\nif (status != napi_ok) return;\n\n// const arg = 1337\nstatus = napi_create_int32(env, 1337, &amp;arg);\nif (status != napi_ok) return;\n\nnapi_value* argv = &amp;arg;\nsize_t argc = 1;\n\n// AddTwo(arg);\nnapi_value return_val;\nstatus = napi_call_function(env, global, add_two, argc, argv, &amp;return_val);\nif (status != napi_ok) return;\n\n// Convert the result back to a native type\nint32_t result;\nstatus = napi_get_value_int32(env, return_val, &amp;result);\nif (status != napi_ok) return;\n</code></pre>\n",
"type": "module",
"displayName": "napi_call_function"
},
{
"textRaw": "napi_create_function",
"name": "napi_create_function",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_function(napi_env env,\n const char* utf8name,\n napi_callback cb,\n void* data,\n napi_value* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] utf8Name</code>: The name of the function encoded as UTF8. This is visible\nwithin JavaScript as the new function object&#39;s <code>name</code> property.</li>\n<li><code>[in] cb</code>: The native function which should be called when this function\nobject is invoked.</li>\n<li><code>[in] data</code>: User-provided data context. This will be passed back into the\nfunction when invoked later.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing the JavaScript function object for\nthe newly created function.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API allows an add-on author to create a function object in native code.\nThis is the primary mechanism to allow calling <em>into</em> the add-on&#39;s native code\n<em>from</em> JavaScript.</p>\n<p>The newly created function is not automatically visible from script after this\ncall. Instead, a property must be explicitly set on any object that is visible\nto JavaScript, in order for the function to be accessible from script.</p>\n<p>In order to expose a function as part of the\nadd-on&#39;s module exports, set the newly created function on the exports\nobject. A sample module might look as follows:</p>\n<pre><code class=\"lang-C\">napi_value SayHello(napi_env env, napi_callback_info info) {\n printf(&quot;Hello\\n&quot;);\n return NULL;\n}\n\nnapi_value Init(napi_env env, napi_value exports) {\n napi_status status;\n\n napi_value fn;\n status = napi_create_function(env, NULL, 0, SayHello, NULL, &amp;fn);\n if (status != napi_ok) return NULL;\n\n status = napi_set_named_property(env, exports, &quot;sayHello&quot;, fn);\n if (status != napi_ok) return NULL;\n\n return exports;\n}\n\nNAPI_MODULE(NODE_GYP_MODULE_NAME, Init)\n</code></pre>\n<p>Given the above code, the add-on can be used from JavaScript as follows:</p>\n<pre><code class=\"lang-js\">const myaddon = require(&#39;./addon&#39;);\nmyaddon.sayHello();\n</code></pre>\n<p>The string passed to require is not necessarily the name passed into\n<code>NAPI_MODULE</code> in the earlier snippet but the name of the target in <code>binding.gyp</code>\nresponsible for creating the <code>.node</code> file.</p>\n",
"type": "module",
"displayName": "napi_create_function"
},
{
"textRaw": "napi_get_cb_info",
"name": "napi_get_cb_info",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_cb_info(napi_env env,\n napi_callback_info cbinfo,\n size_t* argc,\n napi_value* argv,\n napi_value* thisArg,\n void** data)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] cbinfo</code>: The callback info passed into the callback function.</li>\n<li><code>[in-out] argc</code>: Specifies the size of the provided <code>argv</code> array\nand receives the actual count of arguments.</li>\n<li><code>[out] argv</code>: Buffer to which the <code>napi_value</code> representing the\narguments are copied. If there are more arguments than the provided\ncount, only the requested number of arguments are copied. If there are fewer\narguments provided than claimed, the rest of <code>argv</code> is filled with <code>napi_value</code>\nvalues that represent <code>undefined</code>.</li>\n<li><code>[out] this</code>: Receives the JavaScript <code>this</code> argument for the call.</li>\n<li><code>[out] data</code>: Receives the data pointer for the callback.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This method is used within a callback function to retrieve details about the\ncall like the arguments and the <code>this</code> pointer from a given callback info.</p>\n",
"type": "module",
"displayName": "napi_get_cb_info"
},
{
"textRaw": "napi_get_new_target",
"name": "napi_get_new_target",
"meta": {
"added": [
"v8.6.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_new_target(napi_env env,\n napi_callback_info cbinfo,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] cbinfo</code>: The callback info passed into the callback function.</li>\n<li><code>[out] result</code>: The <code>new.target</code> of the constructor call.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns the <code>new.target</code> of the constructor call. If the current\ncallback is not a constructor call, the result is <code>NULL</code>.</p>\n",
"type": "module",
"displayName": "napi_get_new_target"
},
{
"textRaw": "napi_new_instance",
"name": "napi_new_instance",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_new_instance(napi_env env,\n napi_value cons,\n size_t argc,\n napi_value* argv,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] cons</code>: <code>napi_value</code> representing the JavaScript function\nto be invoked as a constructor.</li>\n<li><code>[in] argc</code>: The count of elements in the <code>argv</code> array.</li>\n<li><code>[in] argv</code>: Array of JavaScript values as <code>napi_value</code>\nrepresenting the arguments to the constructor.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing the JavaScript object returned,\nwhich in this case is the constructed object.</li>\n</ul>\n<p>This method is used to instantiate a new JavaScript value using a given\n<code>napi_value</code> that represents the constructor for the object. For example,\nconsider the following snippet:</p>\n<pre><code class=\"lang-js\">function MyObject(param) {\n this.param = param;\n}\n\nconst arg = &#39;hello&#39;;\nconst value = new MyObject(arg);\n</code></pre>\n<p>The following can be approximated in N-API using the following snippet:</p>\n<pre><code class=\"lang-C\">// Get the constructor function MyObject\nnapi_value global, constructor, arg, value;\nnapi_status status = napi_get_global(env, &amp;global);\nif (status != napi_ok) return;\n\nstatus = napi_get_named_property(env, global, &quot;MyObject&quot;, &amp;constructor);\nif (status != napi_ok) return;\n\n// const arg = &quot;hello&quot;\nstatus = napi_create_string_utf8(env, &quot;hello&quot;, NAPI_AUTO_LENGTH, &amp;arg);\nif (status != napi_ok) return;\n\nnapi_value* argv = &amp;arg;\nsize_t argc = 1;\n\n// const value = new MyObject(arg)\nstatus = napi_new_instance(env, constructor, argc, argv, &amp;value);\n</code></pre>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n",
"type": "module",
"displayName": "napi_new_instance"
}
],
"type": "misc",
"displayName": "Working with JavaScript Functions"
},
{
"textRaw": "Object Wrap",
"name": "object_wrap",
"desc": "<p>N-API offers a way to &quot;wrap&quot; C++ classes and instances so that the class\nconstructor and methods can be called from JavaScript.</p>\n<ol>\n<li>The <a href=\"#n_api_napi_define_class\"><code>napi_define_class</code></a> API defines a JavaScript class with constructor,\nstatic properties and methods, and instance properties and methods that\ncorrespond to the C++ class.</li>\n<li>When JavaScript code invokes the constructor, the constructor callback\nuses <a href=\"#n_api_napi_wrap\"><code>napi_wrap</code></a> to wrap a new C++ instance in a JavaScript object,\nthen returns the wrapper object.</li>\n<li>When JavaScript code invokes a method or property accessor on the class,\nthe corresponding <code>napi_callback</code> C++ function is invoked. For an instance\ncallback, <a href=\"#n_api_napi_unwrap\"><code>napi_unwrap</code></a> obtains the C++ instance that is the target of\nthe call.</li>\n</ol>\n<p>For wrapped objects it may be difficult to distinguish between a function\ncalled on a class prototype and a function called on an instance of a class.\nA common pattern used to address this problem is to save a persistent\nreference to the class constructor for later <code>instanceof</code> checks.</p>\n<p>As an example:</p>\n<pre><code class=\"lang-C\">napi_value MyClass_constructor = NULL;\nstatus = napi_get_reference_value(env, MyClass::es_constructor, &amp;MyClass_constructor);\nassert(napi_ok == status);\nbool is_instance = false;\nstatus = napi_instanceof(env, es_this, MyClass_constructor, &amp;is_instance);\nassert(napi_ok == status);\nif (is_instance) {\n // napi_unwrap() ...\n} else {\n // otherwise...\n}\n</code></pre>\n<p>The reference must be freed once it is no longer needed.</p>\n",
"modules": [
{
"textRaw": "napi_define_class",
"name": "napi_define_class",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_define_class(napi_env env,\n const char* utf8name,\n size_t length,\n napi_callback constructor,\n void* data,\n size_t property_count,\n const napi_property_descriptor* properties,\n napi_value* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] utf8name</code>: Name of the JavaScript constructor function; this is\nnot required to be the same as the C++ class name, though it is recommended\nfor clarity.</li>\n<li><code>[in] length</code>: The length of the <code>utf8name</code> in bytes, or <code>NAPI_AUTO_LENGTH</code>\nif it is null-terminated.</li>\n<li><code>[in] constructor</code>: Callback function that handles constructing instances\nof the class. (This should be a static method on the class, not an actual\nC++ constructor function.)</li>\n<li><code>[in] data</code>: Optional data to be passed to the constructor callback as\nthe <code>data</code> property of the callback info.</li>\n<li><code>[in] property_count</code>: Number of items in the <code>properties</code> array argument.</li>\n<li><code>[in] properties</code>: Array of property descriptors describing static and\ninstance data properties, accessors, and methods on the class\nSee <code>napi_property_descriptor</code>.</li>\n<li><code>[out] result</code>: A <code>napi_value</code> representing the constructor function for\nthe class.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>Defines a JavaScript class that corresponds to a C++ class, including:</p>\n<ul>\n<li>A JavaScript constructor function that has the class name and invokes the\nprovided C++ constructor callback.</li>\n<li>Properties on the constructor function corresponding to <em>static</em> data\nproperties, accessors, and methods of the C++ class (defined by\nproperty descriptors with the <code>napi_static</code> attribute).</li>\n<li>Properties on the constructor function&#39;s <code>prototype</code> object corresponding to\n<em>non-static</em> data properties, accessors, and methods of the C++ class\n(defined by property descriptors without the <code>napi_static</code> attribute).</li>\n</ul>\n<p>The C++ constructor callback should be a static method on the class that calls\nthe actual class constructor, then wraps the new C++ instance in a JavaScript\nobject, and returns the wrapper object. See <code>napi_wrap()</code> for details.</p>\n<p>The JavaScript constructor function returned from <a href=\"#n_api_napi_define_class\"><code>napi_define_class</code></a> is\noften saved and used later, to construct new instances of the class from native\ncode, and/or check whether provided values are instances of the class. In that\ncase, to prevent the function value from being garbage-collected, create a\npersistent reference to it using <a href=\"#n_api_napi_create_reference\"><code>napi_create_reference</code></a> and ensure the\nreference count is kept &gt;= 1.</p>\n",
"type": "module",
"displayName": "napi_define_class"
},
{
"textRaw": "napi_wrap",
"name": "napi_wrap",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_wrap(napi_env env,\n napi_value js_object,\n void* native_object,\n napi_finalize finalize_cb,\n void* finalize_hint,\n napi_ref* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] js_object</code>: The JavaScript object that will be the wrapper for the\nnative object. This object <em>must</em> have been created from the <code>prototype</code> of\na constructor that was created using <code>napi_define_class()</code>.</li>\n<li><code>[in] native_object</code>: The native instance that will be wrapped in the\nJavaScript object.</li>\n<li><code>[in] finalize_cb</code>: Optional native callback that can be used to free the\nnative instance when the JavaScript object is ready for garbage-collection.</li>\n<li><code>[in] finalize_hint</code>: Optional contextual hint that is passed to the\nfinalize callback.</li>\n<li><code>[out] result</code>: Optional reference to the wrapped object.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>Wraps a native instance in a JavaScript object. The native instance can be\nretrieved later using <code>napi_unwrap()</code>.</p>\n<p>When JavaScript code invokes a constructor for a class that was defined using\n<code>napi_define_class()</code>, the <code>napi_callback</code> for the constructor is invoked.\nAfter constructing an instance of the native class, the callback must then call\n<code>napi_wrap()</code> to wrap the newly constructed instance in the already-created\nJavaScript object that is the <code>this</code> argument to the constructor callback.\n(That <code>this</code> object was created from the constructor function&#39;s <code>prototype</code>,\nso it already has definitions of all the instance properties and methods.)</p>\n<p>Typically when wrapping a class instance, a finalize callback should be\nprovided that simply deletes the native instance that is received as the <code>data</code>\nargument to the finalize callback.</p>\n<p>The optional returned reference is initially a weak reference, meaning it\nhas a reference count of 0. Typically this reference count would be incremented\ntemporarily during async operations that require the instance to remain valid.</p>\n<p><em>Caution</em>: The optional returned reference (if obtained) should be deleted via\n<a href=\"#n_api_napi_delete_reference\"><code>napi_delete_reference</code></a> ONLY in response to the finalize callback\ninvocation. (If it is deleted before then, then the finalize callback may never\nbe invoked.) Therefore, when obtaining a reference a finalize callback is also\nrequired in order to enable correct proper of the reference.</p>\n<p>This API may modify the prototype chain of the wrapper object. Afterward,\nadditional manipulation of the wrapper&#39;s prototype chain may cause\n<code>napi_unwrap()</code> to fail.</p>\n<p>Calling <code>napi_wrap()</code> a second time on an object will return an error. To\nassociate another native instance with the object, use <code>napi_remove_wrap()</code>\nfirst.</p>\n",
"type": "module",
"displayName": "napi_wrap"
},
{
"textRaw": "napi_unwrap",
"name": "napi_unwrap",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_unwrap(napi_env env,\n napi_value js_object,\n void** result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] js_object</code>: The object associated with the native instance.</li>\n<li><code>[out] result</code>: Pointer to the wrapped native instance.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>Retrieves a native instance that was previously wrapped in a JavaScript\nobject using <code>napi_wrap()</code>.</p>\n<p>When JavaScript code invokes a method or property accessor on the class, the\ncorresponding <code>napi_callback</code> is invoked. If the callback is for an instance\nmethod or accessor, then the <code>this</code> argument to the callback is the wrapper\nobject; the wrapped C++ instance that is the target of the call can be obtained\nthen by calling <code>napi_unwrap()</code> on the wrapper object.</p>\n",
"type": "module",
"displayName": "napi_unwrap"
},
{
"textRaw": "napi_remove_wrap",
"name": "napi_remove_wrap",
"meta": {
"added": [
"v8.5.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_remove_wrap(napi_env env,\n napi_value js_object,\n void** result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] js_object</code>: The object associated with the native instance.</li>\n<li><code>[out] result</code>: Pointer to the wrapped native instance.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>Retrieves a native instance that was previously wrapped in the JavaScript\nobject <code>js_object</code> using <code>napi_wrap()</code> and removes the wrapping, thereby\nrestoring the JavaScript object&#39;s prototype chain. If a finalize callback was\nassociated with the wrapping, it will no longer be called when the JavaScript\nobject becomes garbage-collected.</p>\n",
"type": "module",
"displayName": "napi_remove_wrap"
}
],
"type": "misc",
"displayName": "Object Wrap"
},
{
"textRaw": "Simple Asynchronous Operations",
"name": "simple_asynchronous_operations",
"desc": "<p>Addon modules often need to leverage async helpers from libuv as part of their\nimplementation. This allows them to schedule work to be executed asynchronously\nso that their methods can return in advance of the work being completed. This\nis important in order to allow them to avoid blocking overall execution\nof the Node.js application.</p>\n<p>N-API provides an ABI-stable interface for these\nsupporting functions which covers the most common asynchronous use cases.</p>\n<p>N-API defines the <code>napi_work</code> structure which is used to manage\nasynchronous workers. Instances are created/deleted with\n<a href=\"#n_api_napi_create_async_work\"><code>napi_create_async_work</code></a> and <a href=\"#n_api_napi_delete_async_work\"><code>napi_delete_async_work</code></a>.</p>\n<p>The <code>execute</code> and <code>complete</code> callbacks are functions that will be\ninvoked when the executor is ready to execute and when it completes its\ntask respectively.</p>\n<p>The <code>execute</code> function should avoid making any N-API calls\nthat could result in the execution of JavaScript or interaction with\nJavaScript objects. Most often, any code that needs to make N-API\ncalls should be made in <code>complete</code> callback instead.</p>\n<p>These functions implement the following interfaces:</p>\n<pre><code class=\"lang-C\">typedef void (*napi_async_execute_callback)(napi_env env,\n void* data);\ntypedef void (*napi_async_complete_callback)(napi_env env,\n napi_status status,\n void* data);\n</code></pre>\n<p>When these methods are invoked, the <code>data</code> parameter passed will be the\naddon-provided <code>void*</code> data that was passed into the\n<code>napi_create_async_work</code> call.</p>\n<p>Once created the async worker can be queued\nfor execution using the <a href=\"#n_api_napi_queue_async_work\"><code>napi_queue_async_work</code></a> function:</p>\n<pre><code class=\"lang-C\">napi_status napi_queue_async_work(napi_env env,\n napi_async_work work);\n</code></pre>\n<p><a href=\"#n_api_napi_cancel_async_work\"><code>napi_cancel_async_work</code></a> can be used if the work needs\nto be cancelled before the work has started execution.</p>\n<p>After calling <a href=\"#n_api_napi_cancel_async_work\"><code>napi_cancel_async_work</code></a>, the <code>complete</code> callback\nwill be invoked with a status value of <code>napi_cancelled</code>.\nThe work should not be deleted before the <code>complete</code>\ncallback invocation, even when it was cancelled.</p>\n",
"modules": [
{
"textRaw": "napi_create_async_work",
"name": "napi_create_async_work",
"meta": {
"added": [
"v8.0.0"
],
"changes": [
{
"version": "v8.6.0",
"pr-url": "https://github.com/nodejs/node/pull/14697",
"description": "Added `async_resource` and `async_resource_name` parameters."
}
]
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_async_work(napi_env env,\n napi_value async_resource,\n napi_value async_resource_name,\n napi_async_execute_callback execute,\n napi_async_complete_callback complete,\n void* data,\n napi_async_work* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] async_resource</code>: An optional object associated with the async work\nthat will be passed to possible <code>async_hooks</code> <a href=\"async_hooks.html#async_hooks_init_asyncid_type_triggerasyncid_resource\"><code>init</code> hooks</a>.</li>\n<li><code>[in] async_resource_name</code>: Identifier for the kind of resource that is\nbeing provided for diagnostic information exposed by the <code>async_hooks</code> API.</li>\n<li><code>[in] execute</code>: The native function which should be called to execute\nthe logic asynchronously. The given function is called from a worker pool\nthread and can execute in parallel with the main event loop thread.</li>\n<li><code>[in] complete</code>: The native function which will be called when the\nasynchronous logic is completed or is cancelled. The given function is called\nfrom the main event loop thread.</li>\n<li><code>[in] data</code>: User-provided data context. This will be passed back into the\nexecute and complete functions.</li>\n<li><code>[out] result</code>: <code>napi_async_work*</code> which is the handle to the newly created\nasync work.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API allocates a work object that is used to execute logic asynchronously.\nIt should be freed using <a href=\"#n_api_napi_delete_async_work\"><code>napi_delete_async_work</code></a> once the work is no longer\nrequired.</p>\n<p><code>async_resource_name</code> should be a null-terminated, UTF-8-encoded string.</p>\n<p>The <code>async_resource_name</code> identifier is provided by the user and should be\nrepresentative of the type of async work being performed. It is also recommended\nto apply namespacing to the identifier, e.g. by including the module name. See\nthe <a href=\"async_hooks.html#async_hooks_type\"><code>async_hooks</code> documentation</a> for more information.</p>\n",
"type": "module",
"displayName": "napi_create_async_work"
},
{
"textRaw": "napi_delete_async_work",
"name": "napi_delete_async_work",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_delete_async_work(napi_env env,\n napi_async_work work);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] work</code>: The handle returned by the call to <code>napi_create_async_work</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API frees a previously allocated work object.</p>\n<p>This API can be called even if there is a pending JavaScript exception.</p>\n",
"type": "module",
"displayName": "napi_delete_async_work"
},
{
"textRaw": "napi_queue_async_work",
"name": "napi_queue_async_work",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_queue_async_work(napi_env env,\n napi_async_work work);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] work</code>: The handle returned by the call to <code>napi_create_async_work</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API requests that the previously allocated work be scheduled\nfor execution.</p>\n",
"type": "module",
"displayName": "napi_queue_async_work"
},
{
"textRaw": "napi_cancel_async_work",
"name": "napi_cancel_async_work",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_cancel_async_work(napi_env env,\n napi_async_work work);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] work</code>: The handle returned by the call to <code>napi_create_async_work</code>.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API cancels queued work if it has not yet\nbeen started. If it has already started executing, it cannot be\ncancelled and <code>napi_generic_failure</code> will be returned. If successful,\nthe <code>complete</code> callback will be invoked with a status value of\n<code>napi_cancelled</code>. The work should not be deleted before the <code>complete</code>\ncallback invocation, even if it has been successfully cancelled.</p>\n<p>This API can be called even if there is a pending JavaScript exception.</p>\n",
"type": "module",
"displayName": "napi_cancel_async_work"
}
],
"type": "misc",
"displayName": "Simple Asynchronous Operations"
},
{
"textRaw": "Custom Asynchronous Operations",
"name": "custom_asynchronous_operations",
"desc": "<p>The simple asynchronous work APIs above may not be appropriate for every\nscenario. When using any other asynchronous mechanism, the following APIs\nare necessary to ensure an asynchronous operation is properly tracked by\nthe runtime.</p>\n",
"modules": [
{
"textRaw": "napi_async_init",
"name": "napi_async_init",
"meta": {
"added": [
"v8.6.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_async_init(napi_env env,\n napi_value async_resource,\n napi_value async_resource_name,\n napi_async_context* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] async_resource</code>: An optional object associated with the async work\nthat will be passed to possible <code>async_hooks</code> <a href=\"async_hooks.html#async_hooks_init_asyncid_type_triggerasyncid_resource\"><code>init</code> hooks</a>.</li>\n<li><code>[in] async_resource_name</code>: Identifier for the kind of resource\nthat is being provided for diagnostic information exposed by the\n<code>async_hooks</code> API.</li>\n<li><code>[out] result</code>: The initialized async context.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n",
"type": "module",
"displayName": "napi_async_init"
},
{
"textRaw": "napi_async_destroy",
"name": "napi_async_destroy",
"meta": {
"added": [
"v8.6.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_async_destroy(napi_env env,\n napi_async_context async_context);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] async_context</code>: The async context to be destroyed.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API can be called even if there is a pending JavaScript exception.</p>\n",
"type": "module",
"displayName": "napi_async_destroy"
},
{
"textRaw": "napi_make_callback",
"name": "napi_make_callback",
"meta": {
"added": [
"v8.0.0"
],
"changes": [
{
"version": "v8.6.0",
"description": "Added `async_context` parameter."
}
]
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_make_callback(napi_env env,\n napi_async_context async_context,\n napi_value recv,\n napi_value func,\n int argc,\n const napi_value* argv,\n napi_value* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] async_context</code>: Context for the async operation that is\n invoking the callback. This should normally be a value previously\n obtained from <a href=\"#n_api_napi_async_init\"><code>napi_async_init</code></a>. However <code>NULL</code> is also allowed,\n which indicates the current async context (if any) is to be used\n for the callback.</li>\n<li><code>[in] recv</code>: The <code>this</code> object passed to the called function.</li>\n<li><code>[in] func</code>: <code>napi_value</code> representing the JavaScript function\nto be invoked.</li>\n<li><code>[in] argc</code>: The count of elements in the <code>argv</code> array.</li>\n<li><code>[in] argv</code>: Array of JavaScript values as <code>napi_value</code>\nrepresenting the arguments to the function.</li>\n<li><code>[out] result</code>: <code>napi_value</code> representing the JavaScript object returned.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This method allows a JavaScript function object to be called from a native\nadd-on. This API is similar to <code>napi_call_function</code>. However, it is used to call\n<em>from</em> native code back <em>into</em> JavaScript <em>after</em> returning from an async\noperation (when there is no other script on the stack). It is a fairly simple\nwrapper around <code>node::MakeCallback</code>.</p>\n<p>Note it is <em>not</em> necessary to use <code>napi_make_callback</code> from within a\n<code>napi_async_complete_callback</code>; in that situation the callback&#39;s async\ncontext has already been set up, so a direct call to <code>napi_call_function</code>\nis sufficient and appropriate. Use of the <code>napi_make_callback</code> function\nmay be required when implementing custom async behavior that does not use\n<code>napi_create_async_work</code>.</p>\n",
"type": "module",
"displayName": "napi_make_callback"
},
{
"textRaw": "napi_open_callback_scope",
"name": "napi_open_callback_scope",
"meta": {
"added": [
"v9.6.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_open_callback_scope(napi_env env,\n napi_value resource_object,\n napi_async_context context,\n napi_callback_scope* result)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] resource_object</code>: An optional object associated with the async work\nthat will be passed to possible <code>async_hooks</code> <a href=\"async_hooks.html#async_hooks_init_asyncid_type_triggerasyncid_resource\"><code>init</code> hooks</a>.</li>\n<li><code>[in] context</code>: Context for the async operation that is\ninvoking the callback. This should be a value previously obtained\nfrom <a href=\"#n_api_napi_async_init\"><code>napi_async_init</code></a>.</li>\n<li><code>[out] result</code>: The newly created scope.</li>\n</ul>\n<p>There are cases (for example resolving promises) where it is\nnecessary to have the equivalent of the scope associated with a callback\nin place when making certain N-API calls. If there is no other script on\nthe stack the <a href=\"#n_api_napi_open_callback_scope\"><code>napi_open_callback_scope</code></a> and\n<a href=\"#n_api_napi_close_callback_scope\"><code>napi_close_callback_scope</code></a> functions can be used to open/close\nthe required scope.</p>\n",
"type": "module",
"displayName": "napi_open_callback_scope"
},
{
"textRaw": "napi_close_callback_scope",
"name": "napi_close_callback_scope",
"meta": {
"added": [
"v9.6.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_close_callback_scope(napi_env env,\n napi_callback_scope scope)\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] scope</code>: The scope to be closed.</li>\n</ul>\n<p>This API can be called even if there is a pending JavaScript exception.</p>\n",
"type": "module",
"displayName": "napi_close_callback_scope"
}
],
"type": "misc",
"displayName": "Custom Asynchronous Operations"
},
{
"textRaw": "Version Management",
"name": "version_management",
"modules": [
{
"textRaw": "napi_get_node_version",
"name": "napi_get_node_version",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">typedef struct {\n uint32_t major;\n uint32_t minor;\n uint32_t patch;\n const char* release;\n} napi_node_version;\n\nnapi_status napi_get_node_version(napi_env env,\n const napi_node_version** version);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[out] version</code>: A pointer to version information for Node.js itself.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This function fills the <code>version</code> struct with the major, minor, and patch\nversion of Node.js that is currently running, and the <code>release</code> field with the\nvalue of <a href=\"process.html#process_process_release\"><code>process.release.name</code></a>.</p>\n<p>The returned buffer is statically allocated and does not need to be freed.</p>\n",
"type": "module",
"displayName": "napi_get_node_version"
},
{
"textRaw": "napi_get_version",
"name": "napi_get_version",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_get_version(napi_env env,\n uint32_t* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[out] result</code>: The highest version of N-API supported.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API returns the highest N-API version supported by the\nNode.js runtime. N-API is planned to be additive such that\nnewer releases of Node.js may support additional API functions.\nIn order to allow an addon to use a newer function when running with\nversions of Node.js that support it, while providing\nfallback behavior when running with Node.js versions that don&#39;t\nsupport it:</p>\n<ul>\n<li>Call <code>napi_get_version()</code> to determine if the API is available.</li>\n<li>If available, dynamically load a pointer to the function using <code>uv_dlsym()</code>.</li>\n<li>Use the dynamically loaded pointer to invoke the function.</li>\n<li>If the function is not available, provide an alternate implementation\nthat does not use the function.</li>\n</ul>\n",
"type": "module",
"displayName": "napi_get_version"
}
],
"type": "misc",
"displayName": "Version Management"
},
{
"textRaw": "Memory Management",
"name": "memory_management",
"modules": [
{
"textRaw": "napi_adjust_external_memory",
"name": "napi_adjust_external_memory",
"meta": {
"added": [
"v8.5.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_adjust_external_memory(napi_env env,\n int64_t change_in_bytes,\n int64_t* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] change_in_bytes</code>: The change in externally allocated memory that is\nkept alive by JavaScript objects.</li>\n<li><code>[out] result</code>: The adjusted value</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This function gives V8 an indication of the amount of externally allocated\nmemory that is kept alive by JavaScript objects (i.e. a JavaScript object\nthat points to its own memory allocated by a native module). Registering\nexternally allocated memory will trigger global garbage collections more\noften than it would otherwise.</p>\n<!-- it's very convenient to have all the anchors indexed -->\n<!--lint disable no-unused-definitions remark-lint-->\n",
"type": "module",
"displayName": "napi_adjust_external_memory"
}
],
"type": "misc",
"displayName": "Memory Management"
},
{
"textRaw": "Promises",
"name": "promises",
"desc": "<p>N-API provides facilities for creating <code>Promise</code> objects as described in\n<a href=\"https://tc39.github.io/ecma262/#sec-promise-objects\">Section 25.4</a> of the ECMA specification. It implements promises as a pair of\nobjects. When a promise is created by <code>napi_create_promise()</code>, a &quot;deferred&quot;\nobject is created and returned alongside the <code>Promise</code>. The deferred object is\nbound to the created <code>Promise</code> and is the only means to resolve or reject the\n<code>Promise</code> using <code>napi_resolve_deferred()</code> or <code>napi_reject_deferred()</code>. The\ndeferred object that is created by <code>napi_create_promise()</code> is freed by\n<code>napi_resolve_deferred()</code> or <code>napi_reject_deferred()</code>. The <code>Promise</code> object may\nbe returned to JavaScript where it can be used in the usual fashion.</p>\n<p>For example, to create a promise and pass it to an asynchronous worker:</p>\n<pre><code class=\"lang-c\">napi_deferred deferred;\nnapi_value promise;\nnapi_status status;\n\n// Create the promise.\nstatus = napi_create_promise(env, &amp;deferred, &amp;promise);\nif (status != napi_ok) return NULL;\n\n// Pass the deferred to a function that performs an asynchronous action.\ndo_something_asynchronous(deferred);\n\n// Return the promise to JS\nreturn promise;\n</code></pre>\n<p>The above function <code>do_something_asynchronous()</code> would perform its asynchronous\naction and then it would resolve or reject the deferred, thereby concluding the\npromise and freeing the deferred:</p>\n<pre><code class=\"lang-c\">napi_deferred deferred;\nnapi_value undefined;\nnapi_status status;\n\n// Create a value with which to conclude the deferred.\nstatus = napi_get_undefined(env, &amp;undefined);\nif (status != napi_ok) return NULL;\n\n// Resolve or reject the promise associated with the deferred depending on\n// whether the asynchronous action succeeded.\nif (asynchronous_action_succeeded) {\n status = napi_resolve_deferred(env, deferred, undefined);\n} else {\n status = napi_reject_deferred(env, deferred, undefined);\n}\nif (status != napi_ok) return NULL;\n\n// At this point the deferred has been freed, so we should assign NULL to it.\ndeferred = NULL;\n</code></pre>\n",
"modules": [
{
"textRaw": "napi_create_promise",
"name": "napi_create_promise",
"meta": {
"added": [
"v8.5.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_create_promise(napi_env env,\n napi_deferred* deferred,\n napi_value* promise);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[out] deferred</code>: A newly created deferred object which can later be passed to\n<code>napi_resolve_deferred()</code> or <code>napi_reject_deferred()</code> to resolve resp. reject\nthe associated promise.</li>\n<li><code>[out] promise</code>: The JavaScript promise associated with the deferred object.</li>\n</ul>\n<p>Returns <code>napi_ok</code> if the API succeeded.</p>\n<p>This API creates a deferred object and a JavaScript promise.</p>\n",
"type": "module",
"displayName": "napi_create_promise"
},
{
"textRaw": "napi_resolve_deferred",
"name": "napi_resolve_deferred",
"meta": {
"added": [
"v8.5.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_resolve_deferred(napi_env env,\n napi_deferred deferred,\n napi_value resolution);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] deferred</code>: The deferred object whose associated promise to resolve.</li>\n<li><code>[in] resolution</code>: The value with which to resolve the promise.</li>\n</ul>\n<p>This API resolves a JavaScript promise by way of the deferred object\nwith which it is associated. Thus, it can only be used to resolve JavaScript\npromises for which the corresponding deferred object is available. This\neffectively means that the promise must have been created using\n<code>napi_create_promise()</code> and the deferred object returned from that call must\nhave been retained in order to be passed to this API.</p>\n<p>The deferred object is freed upon successful completion.</p>\n",
"type": "module",
"displayName": "napi_resolve_deferred"
},
{
"textRaw": "napi_reject_deferred",
"name": "napi_reject_deferred",
"meta": {
"added": [
"v8.5.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_reject_deferred(napi_env env,\n napi_deferred deferred,\n napi_value rejection);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] deferred</code>: The deferred object whose associated promise to resolve.</li>\n<li><code>[in] rejection</code>: The value with which to reject the promise.</li>\n</ul>\n<p>This API rejects a JavaScript promise by way of the deferred object\nwith which it is associated. Thus, it can only be used to reject JavaScript\npromises for which the corresponding deferred object is available. This\neffectively means that the promise must have been created using\n<code>napi_create_promise()</code> and the deferred object returned from that call must\nhave been retained in order to be passed to this API.</p>\n<p>The deferred object is freed upon successful completion.</p>\n",
"type": "module",
"displayName": "napi_reject_deferred"
},
{
"textRaw": "napi_is_promise",
"name": "napi_is_promise",
"meta": {
"added": [
"v8.5.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">napi_status napi_is_promise(napi_env env,\n napi_value promise,\n bool* is_promise);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] promise</code>: The promise to examine</li>\n<li><code>[out] is_promise</code>: Flag indicating whether <code>promise</code> is a native promise\nobject - that is, a promise object created by the underlying engine.</li>\n</ul>\n",
"type": "module",
"displayName": "napi_is_promise"
}
],
"type": "misc",
"displayName": "Promises"
},
{
"textRaw": "Script execution",
"name": "script_execution",
"desc": "<p>N-API provides an API for executing a string containing JavaScript using the\nunderlying JavaScript engine.</p>\n",
"modules": [
{
"textRaw": "napi_run_script",
"name": "napi_run_script",
"meta": {
"added": [
"v8.5.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_run_script(napi_env env,\n napi_value script,\n napi_value* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] script</code>: A JavaScript string containing the script to execute.</li>\n<li><code>[out] result</code>: The value resulting from having executed the script.</li>\n</ul>\n",
"type": "module",
"displayName": "napi_run_script"
}
],
"type": "misc",
"displayName": "Script execution"
},
{
"textRaw": "libuv event loop",
"name": "libuv_event_loop",
"desc": "<p>N-API provides a function for getting the current event loop associated with\na specific <code>napi_env</code>.</p>\n",
"modules": [
{
"textRaw": "napi_get_uv_event_loop",
"name": "napi_get_uv_event_loop",
"meta": {
"added": [
"v9.3.0"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status napi_get_uv_event_loop(napi_env env,\n uv_loop_t** loop);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[out] loop</code>: The current libuv loop instance.</li>\n</ul>\n<!-- it's very convenient to have all the anchors indexed -->\n<!--lint disable no-unused-definitions remark-lint-->\n",
"type": "module",
"displayName": "napi_get_uv_event_loop"
}
],
"type": "misc",
"displayName": "libuv event loop"
},
{
"textRaw": "Asynchronous Thread-safe Function Calls",
"name": "asynchronous_thread-safe_function_calls",
"stability": 1,
"stabilityText": "Experimental",
"desc": "<p>JavaScript functions can normally only be called from a native addon&#39;s main\nthread. If an addon creates additional threads, then N-API functions that\nrequire a <code>napi_env</code>, <code>napi_value</code>, or <code>napi_ref</code> must not be called from those\nthreads.</p>\n<p>When an addon has additional threads and JavaScript functions need to be invoked\nbased on the processing completed by those threads, those threads must\ncommunicate with the addon&#39;s main thread so that the main thread can invoke the\nJavaScript function on their behalf. The thread-safe function APIs provide an\neasy way to do this.</p>\n<p>These APIs provide the type <code>napi_threadsafe_function</code> as well as APIs to\ncreate, destroy, and call objects of this type.\n<code>napi_create_threadsafe_function()</code> creates a persistent reference to a\n<code>napi_value</code> that holds a JavaScript function which can be called from multiple\nthreads. The calls happen asynchronously. This means that values with which the\nJavaScript callback is to be called will be placed in a queue, and, for each\nvalue in the queue, a call will eventually be made to the JavaScript function.</p>\n<p>Upon creation of a <code>napi_threadsafe_function</code> a <code>napi_finalize</code> callback can be\nprovided. This callback will be invoked on the main thread when the thread-safe\nfunction is about to be destroyed. It receives the context and the finalize data\ngiven during construction, and provides an opportunity for cleaning up after the\nthreads e.g. by calling <code>uv_thread_join()</code>. <strong>It is important that, aside from\nthe main loop thread, there be no threads left using the thread-safe function\nafter the finalize callback completes.</strong></p>\n<p>The <code>context</code> given during the call to <code>napi_create_threadsafe_function()</code> can\nbe retrieved from any thread with a call to\n<code>napi_get_threadsafe_function_context()</code>.</p>\n<p><code>napi_call_threadsafe_function()</code> can then be used for initiating a call into\nJavaScript. <code>napi_call_threadsafe_function()</code> accepts a parameter which controls\nwhether the API behaves blockingly. If set to <code>napi_tsfn_nonblocking</code>, the API\nbehaves non-blockingly, returning <code>napi_queue_full</code> if the queue was full,\npreventing data from being successfully added to the queue. If set to\n<code>napi_tsfn_blocking</code>, the API blocks until space becomes available in the queue.\n<code>napi_call_threadsafe_function()</code> never blocks if the thread-safe function was\ncreated with a maximum queue size of 0.</p>\n<p>The actual call into JavaScript is controlled by the callback given via the\n<code>call_js_cb</code> parameter. <code>call_js_cb</code> is invoked on the main thread once for each\nvalue that was placed into the queue by a successful call to\n<code>napi_call_threadsafe_function()</code>. If such a callback is not given, a default\ncallback will be used, and the resulting JavaScript call will have no arguments.\nThe <code>call_js_cb</code> callback receives the JavaScript function to call as a\n<code>napi_value</code> in its parameters, as well as the <code>void*</code> context pointer used when\ncreating the <code>napi_threadsafe_function</code>, and the next data pointer that was\ncreated by one of the secondary threads. The callback can then use an API such\nas <code>napi_call_function()</code> to call into JavaScript.</p>\n<p>The callback may also be invoked with <code>env</code> and <code>call_js_cb</code> both set to <code>NULL</code>\nto indicate that calls into JavaScript are no longer possible, while items\nremain in the queue that may need to be freed. This normally occurs when the\nNode.js process exits while there is a thread-safe function still active.</p>\n<p>It is not necessary to call into JavaScript via <code>napi_make_callback()</code> because\nN-API runs <code>call_js_cb</code> in a context appropriate for callbacks.</p>\n<p>Threads can be added to and removed from a <code>napi_threadsafe_function</code> object\nduring its existence. Thus, in addition to specifying an initial number of\nthreads upon creation, <code>napi_acquire_threadsafe_function</code> can be called to\nindicate that a new thread will start making use of the thread-safe function.\nSimilarly, <code>napi_release_threadsafe_function</code> can be called to indicate that an\nexisting thread will stop making use of the thread-safe function.</p>\n<p><code>napi_threadsafe_function</code> objects are destroyed when every thread which uses\nthe object has called <code>napi_release_threadsafe_function()</code> or has received a\nreturn status of <code>napi_closing</code> in response to a call to\n<code>napi_call_threadsafe_function</code>. The queue is emptied before the\n<code>napi_threadsafe_function</code> is destroyed. It is important that\n<code>napi_release_threadsafe_function()</code> be the last API call made in conjunction\nwith a given <code>napi_threadsafe_function</code>, because after the call completes, there\nis no guarantee that the <code>napi_threadsafe_function</code> is still allocated. For the\nsame reason it is also important that no more use be made of a thread-safe\nfunction after receiving a return value of <code>napi_closing</code> in response to a call\nto <code>napi_call_threadsafe_function</code>. Data associated with the\n<code>napi_threadsafe_function</code> can be freed in its <code>napi_finalize</code> callback which\nwas passed to <code>napi_create_threadsafe_function()</code>.</p>\n<p>Once the number of threads making use of a <code>napi_threadsafe_function</code> reaches\nzero, no further threads can start making use of it by calling\n<code>napi_acquire_threadsafe_function()</code>. In fact, all subsequent API calls\nassociated with it, except <code>napi_release_threadsafe_function()</code>, will return an\nerror value of <code>napi_closing</code>.</p>\n<p>The thread-safe function can be &quot;aborted&quot; by giving a value of <code>napi_tsfn_abort</code>\nto <code>napi_release_threadsafe_function()</code>. This will cause all subsequent APIs\nassociated with the thread-safe function except\n<code>napi_release_threadsafe_function()</code> to return <code>napi_closing</code> even before its\nreference count reaches zero. In particular, <code>napi_call_threadsafe_function()</code>\nwill return <code>napi_closing</code>, thus informing the threads that it is no longer\npossible to make asynchronous calls to the thread-safe function. This can be\nused as a criterion for terminating the thread. <strong>Upon receiving a return value\nof <code>napi_closing</code> from <code>napi_call_threadsafe_function()</code> a thread must make no\nfurther use of the thread-safe function because it is no longer guaranteed to\nbe allocated.</strong></p>\n<p>Similarly to libuv handles, thread-safe functions can be &quot;referenced&quot; and\n&quot;unreferenced&quot;. A &quot;referenced&quot; thread-safe function will cause the event loop on\nthe thread on which it is created to remain alive until the thread-safe function\nis destroyed. In contrast, an &quot;unreferenced&quot; thread-safe function will not\nprevent the event loop from exiting. The APIs <code>napi_ref_threadsafe_function</code> and\n<code>napi_unref_threadsafe_function</code> exist for this purpose.</p>\n",
"modules": [
{
"textRaw": "napi_create_threadsafe_function",
"name": "napi_create_threadsafe_function",
"stability": 1,
"stabilityText": "Experimental",
"meta": {
"added": [
"REPLACEME"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status\nnapi_create_threadsafe_function(napi_env env,\n napi_value func,\n napi_value async_resource,\n napi_value async_resource_name,\n size_t max_queue_size,\n size_t initial_thread_count,\n void* thread_finalize_data,\n napi_finalize thread_finalize_cb,\n void* context,\n napi_threadsafe_function_call_js call_js_cb,\n napi_threadsafe_function* result);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] func</code>: The JavaScript function to call from another thread.</li>\n<li><code>[in] async_resource</code>: An optional object associated with the async work that\nwill be passed to possible <code>async_hooks</code> <a href=\"async_hooks.html#async_hooks_init_asyncid_type_triggerasyncid_resource\"><code>init</code> hooks</a>.</li>\n<li><code>[in] async_resource_name</code>: A JavaScript string to provide an identifier for\nthe kind of resource that is being provided for diagnostic information exposed\nby the <code>async_hooks</code> API.</li>\n<li><code>[in] max_queue_size</code>: Maximum size of the queue. <code>0</code> for no limit.</li>\n<li><code>[in] initial_thread_count</code>: The initial number of threads, including the main\nthread, which will be making use of this function.</li>\n<li><code>[in] thread_finalize_data</code>: Data to be passed to <code>thread_finalize_cb</code>.</li>\n<li><code>[in] thread_finalize_cb</code>: Function to call when the\n<code>napi_threadsafe_function</code> is being destroyed.</li>\n<li><code>[in] context</code>: Optional data to attach to the resulting\n<code>napi_threadsafe_function</code>.</li>\n<li><code>[in] call_js_cb</code>: Optional callback which calls the JavaScript function in\nresponse to a call on a different thread. This callback will be called on the\nmain thread. If not given, the JavaScript function will be called with no\nparameters and with <code>undefined</code> as its <code>this</code> value.</li>\n<li><code>[out] result</code>: The asynchronous thread-safe JavaScript function.</li>\n</ul>\n",
"type": "module",
"displayName": "napi_create_threadsafe_function"
},
{
"textRaw": "napi_get_threadsafe_function_context",
"name": "napi_get_threadsafe_function_context",
"stability": 1,
"stabilityText": "Experimental",
"meta": {
"added": [
"REPLACEME"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status\nnapi_get_threadsafe_function_context(napi_threadsafe_function func,\n void** result);\n</code></pre>\n<ul>\n<li><code>[in] func</code>: The thread-safe function for which to retrieve the context.</li>\n<li><code>[out] result</code>: The location where to store the context.</li>\n</ul>\n<p>This API may be called from any thread which makes use of <code>func</code>.</p>\n",
"type": "module",
"displayName": "napi_get_threadsafe_function_context"
},
{
"textRaw": "napi_call_threadsafe_function",
"name": "napi_call_threadsafe_function",
"stability": 1,
"stabilityText": "Experimental",
"meta": {
"added": [
"REPLACEME"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status\nnapi_call_threadsafe_function(napi_threadsafe_function func,\n void* data,\n napi_threadsafe_function_call_mode is_blocking);\n</code></pre>\n<ul>\n<li><code>[in] func</code>: The asynchronous thread-safe JavaScript function to invoke.</li>\n<li><code>[in] data</code>: Data to send into JavaScript via the callback <code>call_js_cb</code>\nprovided during the creation of the thread-safe JavaScript function.</li>\n<li><code>[in] is_blocking</code>: Flag whose value can be either <code>napi_tsfn_blocking</code> to\nindicate that the call should block if the queue is full or\n<code>napi_tsfn_nonblocking</code> to indicate that the call should return immediately with\na status of <code>napi_queue_full</code> whenever the queue is full.</li>\n</ul>\n<p>This API will return <code>napi_closing</code> if <code>napi_release_threadsafe_function()</code> was\ncalled with <code>abort</code> set to <code>napi_tsfn_abort</code> from any thread. The value is only\nadded to the queue if the API returns <code>napi_ok</code>.</p>\n<p>This API may be called from any thread which makes use of <code>func</code>.</p>\n",
"type": "module",
"displayName": "napi_call_threadsafe_function"
},
{
"textRaw": "napi_acquire_threadsafe_function",
"name": "napi_acquire_threadsafe_function",
"stability": 1,
"stabilityText": "Experimental",
"meta": {
"added": [
"REPLACEME"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status\nnapi_acquire_threadsafe_function(napi_threadsafe_function func);\n</code></pre>\n<ul>\n<li><code>[in] func</code>: The asynchronous thread-safe JavaScript function to start making\nuse of.</li>\n</ul>\n<p>A thread should call this API before passing <code>func</code> to any other thread-safe\nfunction APIs to indicate that it will be making use of <code>func</code>. This prevents\n<code>func</code> from being destroyed when all other threads have stopped making use of\nit.</p>\n<p>This API may be called from any thread which will start making use of <code>func</code>.</p>\n",
"type": "module",
"displayName": "napi_acquire_threadsafe_function"
},
{
"textRaw": "napi_release_threadsafe_function",
"name": "napi_release_threadsafe_function",
"stability": 1,
"stabilityText": "Experimental",
"meta": {
"added": [
"REPLACEME"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status\nnapi_release_threadsafe_function(napi_threadsafe_function func,\n napi_threadsafe_function_release_mode mode);\n</code></pre>\n<ul>\n<li><code>[in] func</code>: The asynchronous thread-safe JavaScript function whose reference\ncount to decrement.</li>\n<li><code>[in] mode</code>: Flag whose value can be either <code>napi_tsfn_release</code> to indicate\nthat the current thread will make no further calls to the thread-safe function,\nor <code>napi_tsfn_abort</code> to indicate that in addition to the current thread, no\nother thread should make any further calls to the thread-safe function. If set\nto <code>napi_tsfn_abort</code>, further calls to <code>napi_call_threadsafe_function()</code> will\nreturn <code>napi_closing</code>, and no further values will be placed in the queue.</li>\n</ul>\n<p>A thread should call this API when it stops making use of <code>func</code>. Passing <code>func</code>\nto any thread-safe APIs after having called this API has undefined results, as\n<code>func</code> may have been destroyed.</p>\n<p>This API may be called from any thread which will stop making use of <code>func</code>.</p>\n",
"type": "module",
"displayName": "napi_release_threadsafe_function"
},
{
"textRaw": "napi_ref_threadsafe_function",
"name": "napi_ref_threadsafe_function",
"stability": 1,
"stabilityText": "Experimental",
"meta": {
"added": [
"REPLACEME"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status\nnapi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] func</code>: The thread-safe function to reference.</li>\n</ul>\n<p>This API is used to indicate that the event loop running on the main thread\nshould not exit until <code>func</code> has been destroyed. Similar to <a href=\"http://docs.libuv.org/en/v1.x/handle.html#c.uv_ref\"><code>uv_ref</code></a> it is\nalso idempotent.</p>\n<p>This API may only be called from the main thread.</p>\n",
"type": "module",
"displayName": "napi_ref_threadsafe_function"
},
{
"textRaw": "napi_unref_threadsafe_function",
"name": "napi_unref_threadsafe_function",
"stability": 1,
"stabilityText": "Experimental",
"meta": {
"added": [
"REPLACEME"
],
"changes": []
},
"desc": "<pre><code class=\"lang-C\">NAPI_EXTERN napi_status\nnapi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func);\n</code></pre>\n<ul>\n<li><code>[in] env</code>: The environment that the API is invoked under.</li>\n<li><code>[in] func</code>: The thread-safe function to unreference.</li>\n</ul>\n<p>This API is used to indicate that the event loop running on the main thread\nmay exit before <code>func</code> is destroyed. Similar to <a href=\"http://docs.libuv.org/en/v1.x/handle.html#c.uv_unref\"><code>uv_unref</code></a> it is also\nidempotent.</p>\n<p>This API may only be called from the main thread.</p>\n",
"type": "module",
"displayName": "napi_unref_threadsafe_function"
}
],
"type": "misc",
"displayName": "Asynchronous Thread-safe Function Calls"
}
]
},
{
"textRaw": "Command Line Options",
"name": "Command Line Options",
"introduced_in": "v5.9.1",
"type": "misc",
"desc": "<p>Node.js comes with a variety of CLI options. These options expose built-in\ndebugging, multiple ways to execute scripts, and other helpful runtime options.</p>\n<p>To view this documentation as a manual page in a terminal, run <code>man node</code>.</p>\n",
"miscs": [
{
"textRaw": "Synopsis",
"name": "synopsis",
"desc": "<p><code>node [options] [V8 options] [script.js | -e &quot;script&quot; | -] [--] [arguments]</code></p>\n<p><code>node debug [script.js | -e &quot;script&quot; | &lt;host&gt;:&lt;port&gt;] …</code></p>\n<p><code>node --v8-options</code></p>\n<p>Execute without arguments to start the <a href=\"repl.html\">REPL</a>.</p>\n<p><em>For more info about <code>node debug</code>, please see the <a href=\"debugger.html\">debugger</a> documentation.</em></p>\n",
"type": "misc",
"displayName": "Synopsis"
},
{
"textRaw": "Options",
"name": "options",
"modules": [
{
"textRaw": "`-`",
"name": "`-`",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<p>Alias for stdin, analogous to the use of - in other command line utilities,\nmeaning that the script will be read from stdin, and the rest of the options\nare passed to that script.</p>\n",
"type": "module",
"displayName": "`-`"
},
{
"textRaw": "`--`",
"name": "`--`",
"meta": {
"added": [
"v6.11.0"
],
"changes": []
},
"desc": "<p>Indicate the end of node options. Pass the rest of the arguments to the script.\nIf no script filename or eval/print script is supplied prior to this, then\nthe next argument will be used as a script filename.</p>\n",
"type": "module",
"displayName": "`--`"
},
{
"textRaw": "`--abort-on-uncaught-exception`",
"name": "`--abort-on-uncaught-exception`",
"meta": {
"added": [
"v0.10"
],
"changes": []
},
"desc": "<p>Aborting instead of exiting causes a core file to be generated for post-mortem\nanalysis using a debugger (such as <code>lldb</code>, <code>gdb</code>, and <code>mdb</code>).</p>\n<p>If this flag is passed, the behavior can still be set to not abort through\n<a href=\"process.html#process_process_setuncaughtexceptioncapturecallback_fn\"><code>process.setUncaughtExceptionCaptureCallback()</code></a> (and through usage of the\n<code>domain</code> module that uses it).</p>\n",
"type": "module",
"displayName": "`--abort-on-uncaught-exception`"
},
{
"textRaw": "`--enable-fips`",
"name": "`--enable-fips`",
"meta": {
"added": [
"v6.0.0"
],
"changes": []
},
"desc": "<p>Enable FIPS-compliant crypto at startup. (Requires Node.js to be built with\n<code>./configure --openssl-fips</code>.)</p>\n",
"type": "module",
"displayName": "`--enable-fips`"
},
{
"textRaw": "`--experimental-modules`",
"name": "`--experimental-modules`",
"meta": {
"added": [
"v8.5.0"
],
"changes": []
},
"desc": "<p>Enable experimental ES module support and caching modules.</p>\n",
"type": "module",
"displayName": "`--experimental-modules`"
},
{
"textRaw": "`--experimental-repl-await`",
"name": "`--experimental-repl-await`",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"desc": "<p>Enable experimental top-level <code>await</code> keyword support in REPL.</p>\n",
"type": "module",
"displayName": "`--experimental-repl-await`"
},
{
"textRaw": "`--experimental-vm-modules`",
"name": "`--experimental-vm-modules`",
"meta": {
"added": [
"v9.6.0"
],
"changes": []
},
"desc": "<p>Enable experimental ES Module support in the <code>vm</code> module.</p>\n",
"type": "module",
"displayName": "`--experimental-vm-modules`"
},
{
"textRaw": "`--experimental-worker`",
"name": "`--experimental-worker`",
"meta": {
"added": [
"v10.5.0"
],
"changes": []
},
"desc": "<p>Enable experimental worker threads using the <code>worker_threads</code> module.</p>\n",
"type": "module",
"displayName": "`--experimental-worker`"
},
{
"textRaw": "`--force-fips`",
"name": "`--force-fips`",
"meta": {
"added": [
"v6.0.0"
],
"changes": []
},
"desc": "<p>Force FIPS-compliant crypto on startup. (Cannot be disabled from script code.)\n(Same requirements as <code>--enable-fips</code>.)</p>\n",
"type": "module",
"displayName": "`--force-fips`"
},
{
"textRaw": "`--icu-data-dir=file`",
"name": "`--icu-data-dir=file`",
"meta": {
"added": [
"v0.11.15"
],
"changes": []
},
"desc": "<p>Specify ICU data load path. (Overrides <code>NODE_ICU_DATA</code>.)</p>\n",
"type": "module",
"displayName": "`--icu-data-dir=file`"
},
{
"textRaw": "`--inspect-brk[=[host:]port]`",
"name": "`--inspect-brk[=[host:]port]`",
"meta": {
"added": [
"v7.6.0"
],
"changes": []
},
"desc": "<p>Activate inspector on <code>host:port</code> and break at start of user script.\nDefault <code>host:port</code> is <code>127.0.0.1:9229</code>.</p>\n",
"type": "module",
"displayName": "`--inspect-brk[=[host:]port]`"
},
{
"textRaw": "`--inspect-port=[host:]port`",
"name": "`--inspect-port=[host:]port`",
"meta": {
"added": [
"v7.6.0"
],
"changes": []
},
"desc": "<p>Set the <code>host:port</code> to be used when the inspector is activated.\nUseful when activating the inspector by sending the <code>SIGUSR1</code> signal.</p>\n<p>Default host is <code>127.0.0.1</code>.</p>\n",
"type": "module",
"displayName": "`--inspect-port=[host:]port`"
},
{
"textRaw": "`--inspect[=[host:]port]`",
"name": "`--inspect[=[host:]port]`",
"meta": {
"added": [
"v6.3.0"
],
"changes": []
},
"desc": "<p>Activate inspector on <code>host:port</code>. Default is <code>127.0.0.1:9229</code>.</p>\n<p>V8 inspector integration allows tools such as Chrome DevTools and IDEs to debug\nand profile Node.js instances. The tools attach to Node.js instances via a\ntcp port and communicate using the <a href=\"https://chromedevtools.github.io/devtools-protocol/\">Chrome DevTools Protocol</a>.</p>\n",
"type": "module",
"displayName": "`--inspect[=[host:]port]`"
},
{
"textRaw": "`--napi-modules`",
"name": "`--napi-modules`",
"meta": {
"added": [
"v7.10.0"
],
"changes": []
},
"desc": "<p>This option is a no-op. It is kept for compatibility.</p>\n",
"type": "module",
"displayName": "`--napi-modules`"
},
{
"textRaw": "`--no-deprecation`",
"name": "`--no-deprecation`",
"meta": {
"added": [
"v0.8.0"
],
"changes": []
},
"desc": "<p>Silence deprecation warnings.</p>\n",
"type": "module",
"displayName": "`--no-deprecation`"
},
{
"textRaw": "`--no-force-async-hooks-checks`",
"name": "`--no-force-async-hooks-checks`",
"meta": {
"added": [
"v9.0.0"
],
"changes": []
},
"desc": "<p>Disables runtime checks for <code>async_hooks</code>. These will still be enabled\ndynamically when <code>async_hooks</code> is enabled.</p>\n",
"type": "module",
"displayName": "`--no-force-async-hooks-checks`"
},
{
"textRaw": "`--no-warnings`",
"name": "`--no-warnings`",
"meta": {
"added": [
"v6.0.0"
],
"changes": []
},
"desc": "<p>Silence all process warnings (including deprecations).</p>\n",
"type": "module",
"displayName": "`--no-warnings`"
},
{
"textRaw": "`--openssl-config=file`",
"name": "`--openssl-config=file`",
"meta": {
"added": [
"v6.9.0"
],
"changes": []
},
"desc": "<p>Load an OpenSSL configuration file on startup. Among other uses, this can be\nused to enable FIPS-compliant crypto if Node.js is built with\n<code>./configure --openssl-fips</code>.</p>\n",
"type": "module",
"displayName": "`--openssl-config=file`"
},
{
"textRaw": "`--pending-deprecation`",
"name": "`--pending-deprecation`",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<p>Emit pending deprecation warnings.</p>\n<p>Pending deprecations are generally identical to a runtime deprecation with the\nnotable exception that they are turned <em>off</em> by default and will not be emitted\nunless either the <code>--pending-deprecation</code> command line flag, or the\n<code>NODE_PENDING_DEPRECATION=1</code> environment variable, is set. Pending deprecations\nare used to provide a kind of selective &quot;early warning&quot; mechanism that\ndevelopers may leverage to detect deprecated API usage.</p>\n",
"type": "module",
"displayName": "`--pending-deprecation`"
},
{
"textRaw": "`--preserve-symlinks`",
"name": "`--preserve-symlinks`",
"meta": {
"added": [
"v6.3.0"
],
"changes": []
},
"desc": "<p>Instructs the module loader to preserve symbolic links when resolving and\ncaching modules.</p>\n<p>By default, when Node.js loads a module from a path that is symbolically linked\nto a different on-disk location, Node.js will dereference the link and use the\nactual on-disk &quot;real path&quot; of the module as both an identifier and as a root\npath to locate other dependency modules. In most cases, this default behavior\nis acceptable. However, when using symbolically linked peer dependencies, as\nillustrated in the example below, the default behavior causes an exception to\nbe thrown if <code>moduleA</code> attempts to require <code>moduleB</code> as a peer dependency:</p>\n<pre><code class=\"lang-text\">{appDir}\n ├── app\n │ ├── index.js\n │ └── node_modules\n │ ├── moduleA -&gt; {appDir}/moduleA\n │ └── moduleB\n │ ├── index.js\n │ └── package.json\n └── moduleA\n ├── index.js\n └── package.json\n</code></pre>\n<p>The <code>--preserve-symlinks</code> command line flag instructs Node.js to use the\nsymlink path for modules as opposed to the real path, allowing symbolically\nlinked peer dependencies to be found.</p>\n<p>Note, however, that using <code>--preserve-symlinks</code> can have other side effects.\nSpecifically, symbolically linked <em>native</em> modules can fail to load if those\nare linked from more than one location in the dependency tree (Node.js would\nsee those as two separate modules and would attempt to load the module multiple\ntimes, causing an exception to be thrown).</p>\n<p>The <code>--preserve-symlinks</code> flag does not apply to the main module, which allows\n<code>node --preserve-symlinks node_module/.bin/&lt;foo&gt;</code> to work. To apply the same\nbehavior for the main module, also use <code>--preserve-symlinks-main</code>.</p>\n",
"type": "module",
"displayName": "`--preserve-symlinks`"
},
{
"textRaw": "`--preserve-symlinks-main`",
"name": "`--preserve-symlinks-main`",
"meta": {
"added": [
"v10.2.0"
],
"changes": []
},
"desc": "<p>Instructs the module loader to preserve symbolic links when resolving and\ncaching the main module (<code>require.main</code>).</p>\n<p>This flag exists so that the main module can be opted-in to the same behavior\nthat <code>--preserve-symlinks</code> gives to all other imports; they are separate flags,\nhowever, for backward compatibility with older Node.js versions.</p>\n<p>Note that <code>--preserve-symlinks-main</code> does not imply <code>--preserve-symlinks</code>; it\nis expected that <code>--preserve-symlinks-main</code> will be used in addition to\n<code>--preserve-symlinks</code> when it is not desirable to follow symlinks before\nresolving relative paths.</p>\n<p>See <code>--preserve-symlinks</code> for more information.</p>\n",
"type": "module",
"displayName": "`--preserve-symlinks-main`"
},
{
"textRaw": "`--prof`",
"name": "`--prof`",
"meta": {
"added": [
"v2.0.0"
],
"changes": []
},
"desc": "<p>Generate V8 profiler output.</p>\n",
"type": "module",
"displayName": "`--prof`"
},
{
"textRaw": "`--prof-process`",
"name": "`--prof-process`",
"meta": {
"added": [
"v5.2.0"
],
"changes": []
},
"desc": "<p>Process V8 profiler output generated using the V8 option <code>--prof</code>.</p>\n",
"type": "module",
"displayName": "`--prof-process`"
},
{
"textRaw": "`--redirect-warnings=file`",
"name": "`--redirect-warnings=file`",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<p>Write process warnings to the given file instead of printing to stderr. The\nfile will be created if it does not exist, and will be appended to if it does.\nIf an error occurs while attempting to write the warning to the file, the\nwarning will be written to stderr instead.</p>\n",
"type": "module",
"displayName": "`--redirect-warnings=file`"
},
{
"textRaw": "`--throw-deprecation`",
"name": "`--throw-deprecation`",
"meta": {
"added": [
"v0.11.14"
],
"changes": []
},
"desc": "<p>Throw errors for deprecations.</p>\n",
"type": "module",
"displayName": "`--throw-deprecation`"
},
{
"textRaw": "`--tls-cipher-list=list`",
"name": "`--tls-cipher-list=list`",
"meta": {
"added": [
"v4.0.0"
],
"changes": []
},
"desc": "<p>Specify an alternative default TLS cipher list. Requires Node.js to be built\nwith crypto support (default).</p>\n",
"type": "module",
"displayName": "`--tls-cipher-list=list`"
},
{
"textRaw": "`--trace-deprecation`",
"name": "`--trace-deprecation`",
"meta": {
"added": [
"v0.8.0"
],
"changes": []
},
"desc": "<p>Print stack traces for deprecations.</p>\n",
"type": "module",
"displayName": "`--trace-deprecation`"
},
{
"textRaw": "`--trace-event-categories`",
"name": "`--trace-event-categories`",
"meta": {
"added": [
"v7.7.0"
],
"changes": []
},
"desc": "<p>A comma separated list of categories that should be traced when trace event\ntracing is enabled using <code>--trace-events-enabled</code>.</p>\n",
"type": "module",
"displayName": "`--trace-event-categories`"
},
{
"textRaw": "`--trace-event-file-pattern`",
"name": "`--trace-event-file-pattern`",
"meta": {
"added": [
"v9.8.0"
],
"changes": []
},
"desc": "<p>Template string specifying the filepath for the trace event data, it\nsupports <code>${rotation}</code> and <code>${pid}</code>.</p>\n",
"type": "module",
"displayName": "`--trace-event-file-pattern`"
},
{
"textRaw": "`--trace-events-enabled`",
"name": "`--trace-events-enabled`",
"meta": {
"added": [
"v7.7.0"
],
"changes": []
},
"desc": "<p>Enables the collection of trace event tracing information.</p>\n",
"type": "module",
"displayName": "`--trace-events-enabled`"
},
{
"textRaw": "`--trace-sync-io`",
"name": "`--trace-sync-io`",
"meta": {
"added": [
"v2.1.0"
],
"changes": []
},
"desc": "<p>Prints a stack trace whenever synchronous I/O is detected after the first turn\nof the event loop.</p>\n",
"type": "module",
"displayName": "`--trace-sync-io`"
},
{
"textRaw": "`--trace-warnings`",
"name": "`--trace-warnings`",
"meta": {
"added": [
"v6.0.0"
],
"changes": []
},
"desc": "<p>Print stack traces for process warnings (including deprecations).</p>\n",
"type": "module",
"displayName": "`--trace-warnings`"
},
{
"textRaw": "`--track-heap-objects`",
"name": "`--track-heap-objects`",
"meta": {
"added": [
"v2.4.0"
],
"changes": []
},
"desc": "<p>Track heap object allocations for heap snapshots.</p>\n",
"type": "module",
"displayName": "`--track-heap-objects`"
},
{
"textRaw": "`--use-bundled-ca`, `--use-openssl-ca`",
"name": "`--use-bundled-ca`,_`--use-openssl-ca`",
"meta": {
"added": [
"v6.11.0"
],
"changes": []
},
"desc": "<p>Use bundled Mozilla CA store as supplied by current Node.js version\nor use OpenSSL&#39;s default CA store. The default store is selectable\nat build-time.</p>\n<p>The bundled CA store, as supplied by Node.js, is a snapshot of Mozilla CA store\nthat is fixed at release time. It is identical on all supported platforms.</p>\n<p>Using OpenSSL store allows for external modifications of the store. For most\nLinux and BSD distributions, this store is maintained by the distribution\nmaintainers and system administrators. OpenSSL CA store location is dependent on\nconfiguration of the OpenSSL library but this can be altered at runtime using\nenvironment variables.</p>\n<p>See <code>SSL_CERT_DIR</code> and <code>SSL_CERT_FILE</code>.</p>\n",
"type": "module",
"displayName": "`--use-bundled-ca`, `--use-openssl-ca`"
},
{
"textRaw": "`--v8-options`",
"name": "`--v8-options`",
"meta": {
"added": [
"v0.1.3"
],
"changes": []
},
"desc": "<p>Print V8 command line options.</p>\n<p>V8 options allow words to be separated by both dashes (<code>-</code>) or\nunderscores (<code>_</code>).</p>\n<p>For example, <code>--stack-trace-limit</code> is equivalent to <code>--stack_trace_limit</code>.</p>\n",
"type": "module",
"displayName": "`--v8-options`"
},
{
"textRaw": "`--v8-pool-size=num`",
"name": "`--v8-pool-size=num`",
"meta": {
"added": [
"v5.10.0"
],
"changes": []
},
"desc": "<p>Set V8&#39;s thread pool size which will be used to allocate background jobs.</p>\n<p>If set to <code>0</code> then V8 will choose an appropriate size of the thread pool based\non the number of online processors.</p>\n<p>If the value provided is larger than V8&#39;s maximum, then the largest value\nwill be chosen.</p>\n",
"type": "module",
"displayName": "`--v8-pool-size=num`"
},
{
"textRaw": "`--zero-fill-buffers`",
"name": "`--zero-fill-buffers`",
"meta": {
"added": [
"v6.0.0"
],
"changes": []
},
"desc": "<p>Automatically zero-fills all newly allocated <a href=\"buffer.html#buffer_class_buffer\"><code>Buffer</code></a> and <a href=\"buffer.html#buffer_class_slowbuffer\"><code>SlowBuffer</code></a>\ninstances.</p>\n",
"type": "module",
"displayName": "`--zero-fill-buffers`"
},
{
"textRaw": "`-c`, `--check`",
"name": "`-c`,_`--check`",
"meta": {
"added": [
"v5.0.0",
"v4.2.0"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/19600",
"description": "The `--require` option is now supported when checking a file."
}
]
},
"desc": "<p>Syntax check the script without executing.</p>\n",
"type": "module",
"displayName": "`-c`, `--check`"
},
{
"textRaw": "`-e`, `--eval \"script\"`",
"name": "`-e`,_`--eval_\"script\"`",
"meta": {
"added": [
"v0.5.2"
],
"changes": [
{
"version": "v5.11.0",
"pr-url": "https://github.com/nodejs/node/pull/5348",
"description": "Built-in libraries are now available as predefined variables."
}
]
},
"desc": "<p>Evaluate the following argument as JavaScript. The modules which are\npredefined in the REPL can also be used in <code>script</code>.</p>\n<p>On Windows, using <code>cmd.exe</code> a single quote will not work correctly because it\nonly recognizes double <code>&quot;</code> for quoting. In Powershell or Git bash, both <code>&#39;</code>\nand <code>&quot;</code> are usable.</p>\n",
"type": "module",
"displayName": "`-e`, `--eval \"script\"`"
},
{
"textRaw": "`-h`, `--help`",
"name": "`-h`,_`--help`",
"meta": {
"added": [
"v0.1.3"
],
"changes": []
},
"desc": "<p>Print node command line options.\nThe output of this option is less detailed than this document.</p>\n",
"type": "module",
"displayName": "`-h`, `--help`"
},
{
"textRaw": "`-i`, `--interactive`",
"name": "`-i`,_`--interactive`",
"meta": {
"added": [
"v0.7.7"
],
"changes": []
},
"desc": "<p>Opens the REPL even if stdin does not appear to be a terminal.</p>\n",
"type": "module",
"displayName": "`-i`, `--interactive`"
},
{
"textRaw": "`-p`, `--print \"script\"`",
"name": "`-p`,_`--print_\"script\"`",
"meta": {
"added": [
"v0.6.4"
],
"changes": [
{
"version": "v5.11.0",
"pr-url": "https://github.com/nodejs/node/pull/5348",
"description": "Built-in libraries are now available as predefined variables."
}
]
},
"desc": "<p>Identical to <code>-e</code> but prints the result.</p>\n",
"type": "module",
"displayName": "`-p`, `--print \"script\"`"
},
{
"textRaw": "`-r`, `--require module`",
"name": "`-r`,_`--require_module`",
"meta": {
"added": [
"v1.6.0"
],
"changes": []
},
"desc": "<p>Preload the specified module at startup.</p>\n<p>Follows <code>require()</code>&#39;s module resolution\nrules. <code>module</code> may be either a path to a file, or a node module name.</p>\n",
"type": "module",
"displayName": "`-r`, `--require module`"
},
{
"textRaw": "`-v`, `--version`",
"name": "`-v`,_`--version`",
"meta": {
"added": [
"v0.1.3"
],
"changes": []
},
"desc": "<p>Print node&#39;s version.</p>\n",
"type": "module",
"displayName": "`-v`, `--version`"
}
],
"type": "misc",
"displayName": "Options"
},
{
"textRaw": "Environment Variables",
"name": "environment_variables",
"modules": [
{
"textRaw": "`NODE_DEBUG=module[,…]`",
"name": "`node_debug=module[,…]`",
"meta": {
"added": [
"v0.1.32"
],
"changes": []
},
"desc": "<p><code>&#39;,&#39;</code>-separated list of core modules that should print debug information.</p>\n",
"type": "module",
"displayName": "`NODE_DEBUG=module[,…]`"
},
{
"textRaw": "`NODE_DISABLE_COLORS=1`",
"name": "`node_disable_colors=1`",
"meta": {
"added": [
"v0.3.0"
],
"changes": []
},
"desc": "<p>When set to <code>1</code> colors will not be used in the REPL.</p>\n",
"type": "module",
"displayName": "`NODE_DISABLE_COLORS=1`"
},
{
"textRaw": "`NODE_EXTRA_CA_CERTS=file`",
"name": "`node_extra_ca_certs=file`",
"meta": {
"added": [
"v7.3.0"
],
"changes": []
},
"desc": "<p>When set, the well known &quot;root&quot; CAs (like VeriSign) will be extended with the\nextra certificates in <code>file</code>. The file should consist of one or more trusted\ncertificates in PEM format. A message will be emitted (once) with\n<a href=\"process.html#process_process_emitwarning_warning_type_code_ctor\"><code>process.emitWarning()</code></a> if the file is missing or\nmalformed, but any errors are otherwise ignored.</p>\n<p>Note that neither the well known nor extra certificates are used when the <code>ca</code>\noptions property is explicitly specified for a TLS or HTTPS client or server.</p>\n",
"type": "module",
"displayName": "`NODE_EXTRA_CA_CERTS=file`"
},
{
"textRaw": "`NODE_ICU_DATA=file`",
"name": "`node_icu_data=file`",
"meta": {
"added": [
"v0.11.15"
],
"changes": []
},
"desc": "<p>Data path for ICU (<code>Intl</code> object) data. Will extend linked-in data when compiled\nwith small-icu support.</p>\n",
"type": "module",
"displayName": "`NODE_ICU_DATA=file`"
},
{
"textRaw": "`NODE_NO_WARNINGS=1`",
"name": "`node_no_warnings=1`",
"meta": {
"added": [
"v6.11.0"
],
"changes": []
},
"desc": "<p>When set to <code>1</code>, process warnings are silenced.</p>\n",
"type": "module",
"displayName": "`NODE_NO_WARNINGS=1`"
},
{
"textRaw": "`NODE_OPTIONS=options...`",
"name": "`node_options=options...`",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<p>A space-separated list of command line options. <code>options...</code> are interpreted as\nif they had been specified on the command line before the actual command line\n(so they can be overridden). Node.js will exit with an error if an option\nthat is not allowed in the environment is used, such as <code>-p</code> or a script file.</p>\n<p>Node options that are allowed are:</p>\n<ul>\n<li><code>--enable-fips</code></li>\n<li><code>--experimental-modules</code></li>\n<li><code>--experimental-repl-await</code></li>\n<li><code>--experimental-vm-modules</code></li>\n<li><code>--experimental-worker</code></li>\n<li><code>--force-fips</code></li>\n<li><code>--icu-data-dir</code></li>\n<li><code>--inspect</code></li>\n<li><code>--inspect-brk</code></li>\n<li><code>--inspect-port</code></li>\n<li><code>--loader</code></li>\n<li><code>--napi-modules</code></li>\n<li><code>--no-deprecation</code></li>\n<li><code>--no-force-async-hooks-checks</code></li>\n<li><code>--no-warnings</code></li>\n<li><code>--openssl-config</code></li>\n<li><code>--pending-deprecation</code></li>\n<li><code>--redirect-warnings</code></li>\n<li><code>--require</code>, <code>-r</code></li>\n<li><code>--throw-deprecation</code></li>\n<li><code>--tls-cipher-list</code></li>\n<li><code>--trace-deprecation</code></li>\n<li><code>--trace-event-categories</code></li>\n<li><code>--trace-event-file-pattern</code></li>\n<li><code>--trace-events-enabled</code></li>\n<li><code>--trace-sync-io</code></li>\n<li><code>--trace-warnings</code></li>\n<li><code>--track-heap-objects</code></li>\n<li><code>--use-bundled-ca</code></li>\n<li><code>--use-openssl-ca</code></li>\n<li><code>--v8-pool-size</code></li>\n<li><code>--zero-fill-buffers</code></li>\n</ul>\n<p>V8 options that are allowed are:</p>\n<ul>\n<li><code>--abort-on-uncaught-exception</code></li>\n<li><code>--max-old-space-size</code></li>\n<li><code>--perf-basic-prof</code></li>\n<li><code>--perf-prof</code></li>\n<li><code>--stack-trace-limit</code></li>\n</ul>\n",
"type": "module",
"displayName": "`NODE_OPTIONS=options...`"
},
{
"textRaw": "`NODE_PATH=path[:…]`",
"name": "`node_path=path[:…]`",
"meta": {
"added": [
"v0.1.32"
],
"changes": []
},
"desc": "<p><code>&#39;:&#39;</code>-separated list of directories prefixed to the module search path.</p>\n<p>On Windows, this is a <code>&#39;;&#39;</code>-separated list instead.</p>\n",
"type": "module",
"displayName": "`NODE_PATH=path[:…]`"
},
{
"textRaw": "`NODE_PENDING_DEPRECATION=1`",
"name": "`node_pending_deprecation=1`",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<p>When set to <code>1</code>, emit pending deprecation warnings.</p>\n<p>Pending deprecations are generally identical to a runtime deprecation with the\nnotable exception that they are turned <em>off</em> by default and will not be emitted\nunless either the <code>--pending-deprecation</code> command line flag, or the\n<code>NODE_PENDING_DEPRECATION=1</code> environment variable, is set. Pending deprecations\nare used to provide a kind of selective &quot;early warning&quot; mechanism that\ndevelopers may leverage to detect deprecated API usage.</p>\n",
"type": "module",
"displayName": "`NODE_PENDING_DEPRECATION=1`"
},
{
"textRaw": "`NODE_PRESERVE_SYMLINKS=1`",
"name": "`node_preserve_symlinks=1`",
"meta": {
"added": [
"v7.1.0"
],
"changes": []
},
"desc": "<p>When set to <code>1</code>, instructs the module loader to preserve symbolic links when\nresolving and caching modules.</p>\n",
"type": "module",
"displayName": "`NODE_PRESERVE_SYMLINKS=1`"
},
{
"textRaw": "`NODE_REDIRECT_WARNINGS=file`",
"name": "`node_redirect_warnings=file`",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"desc": "<p>When set, process warnings will be emitted to the given file instead of\nprinting to stderr. The file will be created if it does not exist, and will be\nappended to if it does. If an error occurs while attempting to write the\nwarning to the file, the warning will be written to stderr instead. This is\nequivalent to using the <code>--redirect-warnings=file</code> command-line flag.</p>\n",
"type": "module",
"displayName": "`NODE_REDIRECT_WARNINGS=file`"
},
{
"textRaw": "`NODE_REPL_HISTORY=file`",
"name": "`node_repl_history=file`",
"meta": {
"added": [
"v3.0.0"
],
"changes": []
},
"desc": "<p>Path to the file used to store the persistent REPL history. The default path is\n<code>~/.node_repl_history</code>, which is overridden by this variable. Setting the value\nto an empty string (<code>&#39;&#39;</code> or <code>&#39; &#39;</code>) disables persistent REPL history.</p>\n",
"type": "module",
"displayName": "`NODE_REPL_HISTORY=file`"
},
{
"textRaw": "`OPENSSL_CONF=file`",
"name": "`openssl_conf=file`",
"meta": {
"added": [
"v6.11.0"
],
"changes": []
},
"desc": "<p>Load an OpenSSL configuration file on startup. Among other uses, this can be\nused to enable FIPS-compliant crypto if Node.js is built with <code>./configure\n--openssl-fips</code>.</p>\n<p>If the <a href=\"#cli_openssl_config_file\"><code>--openssl-config</code></a> command line option is used, the environment\nvariable is ignored.</p>\n",
"type": "module",
"displayName": "`OPENSSL_CONF=file`"
},
{
"textRaw": "`SSL_CERT_DIR=dir`",
"name": "`ssl_cert_dir=dir`",
"meta": {
"added": [
"v7.7.0"
],
"changes": []
},
"desc": "<p>If <code>--use-openssl-ca</code> is enabled, this overrides and sets OpenSSL&#39;s directory\ncontaining trusted certificates.</p>\n<p>Be aware that unless the child environment is explicitly set, this environment\nvariable will be inherited by any child processes, and if they use OpenSSL, it\nmay cause them to trust the same CAs as node.</p>\n",
"type": "module",
"displayName": "`SSL_CERT_DIR=dir`"
},
{
"textRaw": "`SSL_CERT_FILE=file`",
"name": "`ssl_cert_file=file`",
"meta": {
"added": [
"v7.7.0"
],
"changes": []
},
"desc": "<p>If <code>--use-openssl-ca</code> is enabled, this overrides and sets OpenSSL&#39;s file\ncontaining trusted certificates.</p>\n<p>Be aware that unless the child environment is explicitly set, this environment\nvariable will be inherited by any child processes, and if they use OpenSSL, it\nmay cause them to trust the same CAs as node.</p>\n",
"type": "module",
"displayName": "`SSL_CERT_FILE=file`"
},
{
"textRaw": "`UV_THREADPOOL_SIZE=size`",
"name": "`uv_threadpool_size=size`",
"desc": "<p>Set the number of threads used in libuv&#39;s threadpool to <code>size</code> threads.</p>\n<p>Asynchronous system APIs are used by Node.js whenever possible, but where they\ndo not exist, libuv&#39;s threadpool is used to create asynchronous node APIs based\non synchronous system APIs. Node.js APIs that use the threadpool are:</p>\n<ul>\n<li>all <code>fs</code> APIs, other than the file watcher APIs and those that are explicitly\nsynchronous</li>\n<li><code>crypto.pbkdf2()</code></li>\n<li><code>crypto.randomBytes()</code>, unless it is used without a callback</li>\n<li><code>crypto.randomFill()</code></li>\n<li><code>dns.lookup()</code></li>\n<li>all <code>zlib</code> APIs, other than those that are explicitly synchronous</li>\n</ul>\n<p>Because libuv&#39;s threadpool has a fixed size, it means that if for whatever\nreason any of these APIs takes a long time, other (seemingly unrelated) APIs\nthat run in libuv&#39;s threadpool will experience degraded performance. In order to\nmitigate this issue, one potential solution is to increase the size of libuv&#39;s\nthreadpool by setting the <code>&#39;UV_THREADPOOL_SIZE&#39;</code> environment variable to a value\ngreater than <code>4</code> (its current default value). For more information, see the\n<a href=\"http://docs.libuv.org/en/latest/threadpool.html\">libuv threadpool documentation</a>.</p>\n",
"type": "module",
"displayName": "`UV_THREADPOOL_SIZE=size`"
}
],
"type": "misc",
"displayName": "Environment Variables"
}
]
},
{
"textRaw": "Debugger",
"name": "Debugger",
"introduced_in": "v0.9.12",
"stability": 2,
"stabilityText": "Stable",
"type": "misc",
"desc": "<p>Node.js includes an out-of-process debugging utility accessible via a\n<a href=\"#debugger_v8_inspector_integration_for_node_js\">V8 Inspector</a> and built-in debugging client. To use it, start Node.js\nwith the <code>inspect</code> argument followed by the path to the script to debug; a\nprompt will be displayed indicating successful launch of the debugger:</p>\n<pre><code class=\"lang-txt\">$ node inspect myscript.js\n&lt; Debugger listening on ws://127.0.0.1:9229/80e7a814-7cd3-49fb-921a-2e02228cd5ba\n&lt; For help, see: https://nodejs.org/en/docs/inspector\n&lt; Debugger attached.\nBreak on start in myscript.js:1\n&gt; 1 (function (exports, require, module, __filename, __dirname) { global.x = 5;\n 2 setTimeout(() =&gt; {\n 3 console.log(&#39;world&#39;);\ndebug&gt;\n</code></pre>\n<p>Node.js&#39;s debugger client is not a full-featured debugger, but simple step and\ninspection are possible.</p>\n<p>Inserting the statement <code>debugger;</code> into the source code of a script will\nenable a breakpoint at that position in the code:</p>\n<!-- eslint-disable no-debugger -->\n<pre><code class=\"lang-js\">// myscript.js\nglobal.x = 5;\nsetTimeout(() =&gt; {\n debugger;\n console.log(&#39;world&#39;);\n}, 1000);\nconsole.log(&#39;hello&#39;);\n</code></pre>\n<p>Once the debugger is run, a breakpoint will occur at line 3:</p>\n<pre><code class=\"lang-txt\">$ node inspect myscript.js\n&lt; Debugger listening on ws://127.0.0.1:9229/80e7a814-7cd3-49fb-921a-2e02228cd5ba\n&lt; For help, see: https://nodejs.org/en/docs/inspector\n&lt; Debugger attached.\nBreak on start in myscript.js:1\n&gt; 1 (function (exports, require, module, __filename, __dirname) { global.x = 5;\n 2 setTimeout(() =&gt; {\n 3 debugger;\ndebug&gt; cont\n&lt; hello\nbreak in myscript.js:3\n 1 (function (exports, require, module, __filename, __dirname) { global.x = 5;\n 2 setTimeout(() =&gt; {\n&gt; 3 debugger;\n 4 console.log(&#39;world&#39;);\n 5 }, 1000);\ndebug&gt; next\nbreak in myscript.js:4\n 2 setTimeout(() =&gt; {\n 3 debugger;\n&gt; 4 console.log(&#39;world&#39;);\n 5 }, 1000);\n 6 console.log(&#39;hello&#39;);\ndebug&gt; repl\nPress Ctrl + C to leave debug repl\n&gt; x\n5\n&gt; 2 + 2\n4\ndebug&gt; next\n&lt; world\nbreak in myscript.js:5\n 3 debugger;\n 4 console.log(&#39;world&#39;);\n&gt; 5 }, 1000);\n 6 console.log(&#39;hello&#39;);\n 7\ndebug&gt; .exit\n</code></pre>\n<p>The <code>repl</code> command allows code to be evaluated remotely. The <code>next</code> command\nsteps to the next line. Type <code>help</code> to see what other commands are available.</p>\n<p>Pressing <code>enter</code> without typing a command will repeat the previous debugger\ncommand.</p>\n",
"miscs": [
{
"textRaw": "Watchers",
"name": "watchers",
"desc": "<p>It is possible to watch expression and variable values while debugging. On\nevery breakpoint, each expression from the watchers list will be evaluated\nin the current context and displayed immediately before the breakpoint&#39;s\nsource code listing.</p>\n<p>To begin watching an expression, type <code>watch(&#39;my_expression&#39;)</code>. The command\n<code>watchers</code> will print the active watchers. To remove a watcher, type\n<code>unwatch(&#39;my_expression&#39;)</code>.</p>\n",
"type": "misc",
"displayName": "Watchers"
},
{
"textRaw": "Command reference",
"name": "command_reference",
"modules": [
{
"textRaw": "Stepping",
"name": "Stepping",
"desc": "<ul>\n<li><code>cont</code>, <code>c</code> - Continue execution</li>\n<li><code>next</code>, <code>n</code> - Step next</li>\n<li><code>step</code>, <code>s</code> - Step in</li>\n<li><code>out</code>, <code>o</code> - Step out</li>\n<li><code>pause</code> - Pause running code (like pause button in Developer Tools)</li>\n</ul>\n",
"type": "module",
"displayName": "Breakpoints"
},
{
"textRaw": "Breakpoints",
"name": "breakpoints",
"desc": "<ul>\n<li><code>setBreakpoint()</code>, <code>sb()</code> - Set breakpoint on current line</li>\n<li><code>setBreakpoint(line)</code>, <code>sb(line)</code> - Set breakpoint on specific line</li>\n<li><code>setBreakpoint(&#39;fn()&#39;)</code>, <code>sb(...)</code> - Set breakpoint on a first statement in\nfunctions body</li>\n<li><code>setBreakpoint(&#39;script.js&#39;, 1)</code>, <code>sb(...)</code> - Set breakpoint on first line of\n<code>script.js</code></li>\n<li><code>clearBreakpoint(&#39;script.js&#39;, 1)</code>, <code>cb(...)</code> - Clear breakpoint in <code>script.js</code>\non line 1</li>\n</ul>\n<p>It is also possible to set a breakpoint in a file (module) that\nis not loaded yet:</p>\n<pre><code class=\"lang-txt\">$ node inspect main.js\n&lt; Debugger listening on ws://127.0.0.1:9229/4e3db158-9791-4274-8909-914f7facf3bd\n&lt; For help, see: https://nodejs.org/en/docs/inspector\n&lt; Debugger attached.\nBreak on start in main.js:1\n&gt; 1 (function (exports, require, module, __filename, __dirname) { const mod = require(&#39;./mod.js&#39;);\n 2 mod.hello();\n 3 mod.hello();\ndebug&gt; setBreakpoint(&#39;mod.js&#39;, 22)\nWarning: script &#39;mod.js&#39; was not loaded yet.\ndebug&gt; c\nbreak in mod.js:22\n 20 // USE OR OTHER DEALINGS IN THE SOFTWARE.\n 21\n&gt;22 exports.hello = function() {\n 23 return &#39;hello from module&#39;;\n 24 };\ndebug&gt;\n</code></pre>\n",
"type": "module",
"displayName": "Breakpoints"
},
{
"textRaw": "Execution control",
"name": "Execution control",
"desc": "<ul>\n<li><code>run</code> - Run script (automatically runs on debugger&#39;s start)</li>\n<li><code>restart</code> - Restart script</li>\n<li><code>kill</code> - Kill script</li>\n</ul>\n",
"type": "module",
"displayName": "Various"
},
{
"textRaw": "Various",
"name": "various",
"desc": "<ul>\n<li><code>scripts</code> - List all loaded scripts</li>\n<li><code>version</code> - Display V8&#39;s version</li>\n</ul>\n",
"type": "module",
"displayName": "Various"
}
],
"type": "misc",
"displayName": "Command reference"
},
{
"textRaw": "Advanced Usage",
"name": "advanced_usage",
"modules": [
{
"textRaw": "V8 Inspector Integration for Node.js",
"name": "v8_inspector_integration_for_node.js",
"desc": "<p>V8 Inspector integration allows attaching Chrome DevTools to Node.js\ninstances for debugging and profiling. It uses the\n<a href=\"https://chromedevtools.github.io/devtools-protocol/\">Chrome DevTools Protocol</a>.</p>\n<p>V8 Inspector can be enabled by passing the <code>--inspect</code> flag when starting a\nNode.js application. It is also possible to supply a custom port with that flag,\ne.g. <code>--inspect=9222</code> will accept DevTools connections on port 9222.</p>\n<p>To break on the first line of the application code, pass the <code>--inspect-brk</code>\nflag instead of <code>--inspect</code>.</p>\n<pre><code class=\"lang-txt\">$ node --inspect index.js\nDebugger listening on 127.0.0.1:9229.\nTo start debugging, open the following URL in Chrome:\n chrome-devtools://devtools/bundled/js_app.html?experiments=true&amp;v8only=true&amp;ws=127.0.0.1:9229/dc9010dd-f8b8-4ac5-a510-c1a114ec7d29\n</code></pre>\n<p>(In the example above, the UUID dc9010dd-f8b8-4ac5-a510-c1a114ec7d29\nat the end of the URL is generated on the fly, it varies in different\ndebugging sessions.)</p>\n<p>If the Chrome browser is older than 66.0.3345.0,\nuse <code>inspector.html</code> instead of <code>js_app.html</code> in the above URL.</p>\n",
"type": "module",
"displayName": "V8 Inspector Integration for Node.js"
}
],
"type": "misc",
"displayName": "Advanced Usage"
}
]
},
{
"textRaw": "Deprecated APIs",
"name": "Deprecated APIs",
"introduced_in": "v7.7.0",
"type": "misc",
"desc": "<p>Node.js may deprecate APIs when either: (a) use of the API is considered to be\nunsafe, (b) an improved alternative API is available, or (c) breaking changes to\nthe API are expected in a future major release.</p>\n<p>Node.js utilizes three kinds of Deprecations:</p>\n<ul>\n<li>Documentation-only</li>\n<li>Runtime</li>\n<li>End-of-Life</li>\n</ul>\n<p>A Documentation-only deprecation is one that is expressed only within the\nNode.js API docs. These generate no side-effects while running Node.js.\nSome Documentation-only deprecations trigger a runtime warning when launched\nwith <a href=\"cli.html#cli_pending_deprecation\"><code>--pending-deprecation</code></a> flag (or its alternative,\n<code>NODE_PENDING_DEPRECATION=1</code> environment variable), similarly to Runtime\ndeprecations below. Documentation-only deprecations that support that flag\nare explicitly labeled as such in the\n<a href=\"#deprecations_list_of_deprecated_apis\">list of Deprecated APIs</a>.</p>\n<p>A Runtime deprecation will, by default, generate a process warning that will\nbe printed to <code>stderr</code> the first time the deprecated API is used. When the\n<code>--throw-deprecation</code> command-line flag is used, a Runtime deprecation will\ncause an error to be thrown.</p>\n<p>An End-of-Life deprecation is used when functionality is or will soon be removed\nfrom Node.js.</p>\n",
"miscs": [
{
"textRaw": "Revoking deprecations",
"name": "revoking_deprecations",
"desc": "<p>Occasionally, the deprecation of an API may be reversed. In such situations,\nthis document will be updated with information relevant to the decision.\nHowever, the deprecation identifier will not be modified.</p>\n",
"type": "misc",
"displayName": "Revoking deprecations"
},
{
"textRaw": "List of Deprecated APIs",
"name": "list_of_deprecated_apis",
"desc": "<p><a id=\"DEP0001\"></a></p>\n",
"modules": [
{
"textRaw": "DEP0001: http.OutgoingMessage.prototype.flush",
"name": "dep0001:_http.outgoingmessage.prototype.flush",
"desc": "<p>Type: Runtime</p>\n<p>The <code>OutgoingMessage.prototype.flush()</code> method is deprecated. Use\n<code>OutgoingMessage.prototype.flushHeaders()</code> instead.</p>\n<p><a id=\"DEP0002\"></a></p>\n",
"type": "module",
"displayName": "DEP0001: http.OutgoingMessage.prototype.flush"
},
{
"textRaw": "DEP0002: require('\\_linklist')",
"name": "dep0002:_require('\\_linklist')",
"desc": "<p>Type: End-of-Life</p>\n<p>The <code>_linklist</code> module is deprecated. Please use a userland alternative.</p>\n<p><a id=\"DEP0003\"></a></p>\n",
"type": "module",
"displayName": "DEP0002: require('\\_linklist')"
},
{
"textRaw": "DEP0003: \\_writableState.buffer",
"name": "dep0003:_\\_writablestate.buffer",
"desc": "<p>Type: Runtime</p>\n<p>The <code>_writableState.buffer</code> property is deprecated. Use the\n<code>_writableState.getBuffer()</code> method instead.</p>\n<p><a id=\"DEP0004\"></a></p>\n",
"type": "module",
"displayName": "DEP0003: \\_writableState.buffer"
},
{
"textRaw": "DEP0004: CryptoStream.prototype.readyState",
"name": "dep0004:_cryptostream.prototype.readystate",
"desc": "<p>Type: Documentation-only</p>\n<p>The <code>CryptoStream.prototype.readyState</code> property is deprecated and should not\nbe used.</p>\n<p><a id=\"DEP0005\"></a></p>\n",
"type": "module",
"displayName": "DEP0004: CryptoStream.prototype.readyState"
},
{
"textRaw": "DEP0005: Buffer() constructor",
"name": "dep0005:_buffer()_constructor",
"desc": "<p>Type: Runtime (supports <a href=\"cli.html#cli_pending_deprecation\"><code>--pending-deprecation</code></a>)</p>\n<p>The <code>Buffer()</code> function and <code>new Buffer()</code> constructor are deprecated due to\nAPI usability issues that can potentially lead to accidental security issues.</p>\n<p>As an alternative, use of the following methods of constructing <code>Buffer</code> objects\nis strongly recommended:</p>\n<ul>\n<li><a href=\"buffer.html#buffer_class_method_buffer_alloc_size_fill_encoding\"><code>Buffer.alloc(size[, fill[, encoding]])</code></a> - Create a <code>Buffer</code> with\n<em>initialized</em> memory.</li>\n<li><a href=\"buffer.html#buffer_class_method_buffer_allocunsafe_size\"><code>Buffer.allocUnsafe(size)</code></a> - Create a <code>Buffer</code> with\n<em>uninitialized</em> memory.</li>\n<li><a href=\"buffer.html#buffer_class_method_buffer_allocunsafeslow_size\"><code>Buffer.allocUnsafeSlow(size)</code></a> - Create a <code>Buffer</code> with <em>uninitialized</em>\n memory.</li>\n<li><a href=\"buffer.html#buffer_class_method_buffer_from_array\"><code>Buffer.from(array)</code></a> - Create a <code>Buffer</code> with a copy of <code>array</code></li>\n<li><a href=\"buffer.html#buffer_class_method_buffer_from_arraybuffer_byteoffset_length\"><code>Buffer.from(arrayBuffer[, byteOffset[, length]])</code></a> -\nCreate a <code>Buffer</code> that wraps the given <code>arrayBuffer</code>.</li>\n<li><a href=\"buffer.html#buffer_class_method_buffer_from_buffer\"><code>Buffer.from(buffer)</code></a> - Create a <code>Buffer</code> that copies <code>buffer</code>.</li>\n<li><a href=\"buffer.html#buffer_class_method_buffer_from_string_encoding\"><code>Buffer.from(string[, encoding])</code></a> - Create a <code>Buffer</code>\nthat copies <code>string</code>.</li>\n</ul>\n<p>As of v10.0.0, a deprecation warning is printed at runtime when\n<code>--pending-deprecation</code> is used or when the calling code is\noutside <code>node_modules</code> in order to better target developers, rather than users.</p>\n<p><a id=\"DEP0006\"></a></p>\n",
"type": "module",
"displayName": "DEP0005: Buffer() constructor"
},
{
"textRaw": "DEP0006: child\\_process options.customFds",
"name": "dep0006:_child\\_process_options.customfds",
"desc": "<p>Type: Runtime</p>\n<p>Within the <a href=\"child_process.html\"><code>child_process</code></a> module&#39;s <code>spawn()</code>, <code>fork()</code>, and <code>exec()</code>\nmethods, the <code>options.customFds</code> option is deprecated. The <code>options.stdio</code>\noption should be used instead.</p>\n<p><a id=\"DEP0007\"></a></p>\n",
"type": "module",
"displayName": "DEP0006: child\\_process options.customFds"
},
{
"textRaw": "DEP0007: Replace cluster worker.suicide with worker.exitedAfterDisconnect",
"name": "dep0007:_replace_cluster_worker.suicide_with_worker.exitedafterdisconnect",
"desc": "<p>Type: End-of-Life</p>\n<p>In an earlier version of the Node.js <code>cluster</code>, a boolean property with the name\n<code>suicide</code> was added to the <code>Worker</code> object. The intent of this property was to\nprovide an indication of how and why the <code>Worker</code> instance exited. In Node.js\n6.0.0, the old property was deprecated and replaced with a new\n<a href=\"cluster.html#cluster_worker_exitedafterdisconnect\"><code>worker.exitedAfterDisconnect</code></a> property. The old property name did not\nprecisely describe the actual semantics and was unnecessarily emotion-laden.</p>\n<p><a id=\"DEP0008\"></a></p>\n",
"type": "module",
"displayName": "DEP0007: Replace cluster worker.suicide with worker.exitedAfterDisconnect"
},
{
"textRaw": "DEP0008: require('constants')",
"name": "dep0008:_require('constants')",
"desc": "<p>Type: Documentation-only</p>\n<p>The <code>constants</code> module is deprecated. When requiring access to constants\nrelevant to specific Node.js builtin modules, developers should instead refer\nto the <code>constants</code> property exposed by the relevant module. For instance,\n<code>require(&#39;fs&#39;).constants</code> and <code>require(&#39;os&#39;).constants</code>.</p>\n<p><a id=\"DEP0009\"></a></p>\n",
"type": "module",
"displayName": "DEP0008: require('constants')"
},
{
"textRaw": "DEP0009: crypto.pbkdf2 without digest",
"name": "dep0009:_crypto.pbkdf2_without_digest",
"desc": "<p>Type: End-of-Life</p>\n<p>Use of the <a href=\"crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback\"><code>crypto.pbkdf2()</code></a> API without specifying a digest was deprecated\nin Node.js 6.0 because the method defaulted to using the non-recommended\n<code>&#39;SHA1&#39;</code> digest. Previously, a deprecation warning was printed. Starting in\nNode.js 8.0.0, calling <code>crypto.pbkdf2()</code> or <code>crypto.pbkdf2Sync()</code> with an\nundefined <code>digest</code> will throw a <code>TypeError</code>.</p>\n<p><a id=\"DEP0010\"></a></p>\n",
"type": "module",
"displayName": "DEP0009: crypto.pbkdf2 without digest"
},
{
"textRaw": "DEP0010: crypto.createCredentials",
"name": "dep0010:_crypto.createcredentials",
"desc": "<p>Type: Runtime</p>\n<p>The <a href=\"crypto.html#crypto_crypto_createcredentials_details\"><code>crypto.createCredentials()</code></a> API is deprecated. Please use\n<a href=\"tls.html#tls_tls_createsecurecontext_options\"><code>tls.createSecureContext()</code></a> instead.</p>\n<p><a id=\"DEP0011\"></a></p>\n",
"type": "module",
"displayName": "DEP0010: crypto.createCredentials"
},
{
"textRaw": "DEP0011: crypto.Credentials",
"name": "dep0011:_crypto.credentials",
"desc": "<p>Type: Runtime</p>\n<p>The <code>crypto.Credentials</code> class is deprecated. Please use <a href=\"tls.html#tls_tls_createsecurecontext_options\"><code>tls.SecureContext</code></a>\ninstead.</p>\n<p><a id=\"DEP0012\"></a></p>\n",
"type": "module",
"displayName": "DEP0011: crypto.Credentials"
},
{
"textRaw": "DEP0012: Domain.dispose",
"name": "dep0012:_domain.dispose",
"desc": "<p>Type: End-of-Life</p>\n<p><code>Domain.dispose()</code> has been removed. Recover from failed I/O actions\nexplicitly via error event handlers set on the domain instead.</p>\n<p><a id=\"DEP0013\"></a></p>\n",
"type": "module",
"displayName": "DEP0012: Domain.dispose"
},
{
"textRaw": "DEP0013: fs asynchronous function without callback",
"name": "dep0013:_fs_asynchronous_function_without_callback",
"desc": "<p>Type: End-of-Life</p>\n<p>Calling an asynchronous function without a callback throws a <code>TypeError</code>\nin Node.js 10.0.0 onwards. (See <a href=\"https://github.com/nodejs/node/pull/12562\">https://github.com/nodejs/node/pull/12562</a>.)</p>\n<p><a id=\"DEP0014\"></a></p>\n",
"type": "module",
"displayName": "DEP0013: fs asynchronous function without callback"
},
{
"textRaw": "DEP0014: fs.read legacy String interface",
"name": "dep0014:_fs.read_legacy_string_interface",
"desc": "<p>Type: End-of-Life</p>\n<p>The <a href=\"fs.html#fs_fs_read_fd_buffer_offset_length_position_callback\"><code>fs.read()</code></a> legacy <code>String</code> interface is deprecated. Use the <code>Buffer</code>\nAPI as mentioned in the documentation instead.</p>\n<p><a id=\"DEP0015\"></a></p>\n",
"type": "module",
"displayName": "DEP0014: fs.read legacy String interface"
},
{
"textRaw": "DEP0015: fs.readSync legacy String interface",
"name": "dep0015:_fs.readsync_legacy_string_interface",
"desc": "<p>Type: End-of-Life</p>\n<p>The <a href=\"fs.html#fs_fs_readsync_fd_buffer_offset_length_position\"><code>fs.readSync()</code></a> legacy <code>String</code> interface is deprecated. Use the\n<code>Buffer</code> API as mentioned in the documentation instead.</p>\n<p><a id=\"DEP0016\"></a></p>\n",
"type": "module",
"displayName": "DEP0015: fs.readSync legacy String interface"
},
{
"textRaw": "DEP0016: GLOBAL/root",
"name": "dep0016:_global/root",
"desc": "<p>Type: Runtime</p>\n<p>The <code>GLOBAL</code> and <code>root</code> aliases for the <code>global</code> property are deprecated\nand should no longer be used.</p>\n<p><a id=\"DEP0017\"></a></p>\n",
"type": "module",
"displayName": "DEP0016: GLOBAL/root"
},
{
"textRaw": "DEP0017: Intl.v8BreakIterator",
"name": "dep0017:_intl.v8breakiterator",
"desc": "<p>Type: End-of-Life</p>\n<p><code>Intl.v8BreakIterator</code> was a non-standard extension and has been removed.\nSee <a href=\"https://github.com/tc39/proposal-intl-segmenter\"><code>Intl.Segmenter</code></a>.</p>\n<p><a id=\"DEP0018\"></a></p>\n",
"type": "module",
"displayName": "DEP0017: Intl.v8BreakIterator"
},
{
"textRaw": "DEP0018: Unhandled promise rejections",
"name": "dep0018:_unhandled_promise_rejections",
"desc": "<p>Type: Runtime</p>\n<p>Unhandled promise rejections are deprecated. In the future, promise rejections\nthat are not handled will terminate the Node.js process with a non-zero exit\ncode.</p>\n<p><a id=\"DEP0019\"></a></p>\n",
"type": "module",
"displayName": "DEP0018: Unhandled promise rejections"
},
{
"textRaw": "DEP0019: require('.') resolved outside directory",
"name": "dep0019:_require('.')_resolved_outside_directory",
"desc": "<p>Type: Runtime</p>\n<p>In certain cases, <code>require(&#39;.&#39;)</code> may resolve outside the package directory.\nThis behavior is deprecated and will be removed in a future major Node.js\nrelease.</p>\n<p><a id=\"DEP0020\"></a></p>\n",
"type": "module",
"displayName": "DEP0019: require('.') resolved outside directory"
},
{
"textRaw": "DEP0020: Server.connections",
"name": "dep0020:_server.connections",
"desc": "<p>Type: Runtime</p>\n<p>The <a href=\"net.html#net_server_connections\"><code>Server.connections</code></a> property is deprecated. Please use the\n<a href=\"net.html#net_server_getconnections_callback\"><code>Server.getConnections()</code></a> method instead.</p>\n<p><a id=\"DEP0021\"></a></p>\n",
"type": "module",
"displayName": "DEP0020: Server.connections"
},
{
"textRaw": "DEP0021: Server.listenFD",
"name": "dep0021:_server.listenfd",
"desc": "<p>Type: Runtime</p>\n<p>The <code>Server.listenFD()</code> method is deprecated. Please use\n<a href=\"net.html#net_server_listen_handle_backlog_callback\"><code>Server.listen({fd: &lt;number&gt;})</code></a> instead.</p>\n<p><a id=\"DEP0022\"></a></p>\n",
"type": "module",
"displayName": "DEP0021: Server.listenFD"
},
{
"textRaw": "DEP0022: os.tmpDir()",
"name": "dep0022:_os.tmpdir()",
"desc": "<p>Type: Runtime</p>\n<p>The <code>os.tmpDir()</code> API is deprecated. Please use <a href=\"os.html#os_os_tmpdir\"><code>os.tmpdir()</code></a> instead.</p>\n<p><a id=\"DEP0023\"></a></p>\n",
"type": "module",
"displayName": "DEP0022: os.tmpDir()"
},
{
"textRaw": "DEP0023: os.getNetworkInterfaces()",
"name": "dep0023:_os.getnetworkinterfaces()",
"desc": "<p>Type: Runtime</p>\n<p>The <code>os.getNetworkInterfaces()</code> method is deprecated. Please use the\n<a href=\"os.html#os_os_networkinterfaces\"><code>os.networkInterfaces</code></a> property instead.</p>\n<p><a id=\"DEP0024\"></a></p>\n",
"type": "module",
"displayName": "DEP0023: os.getNetworkInterfaces()"
},
{
"textRaw": "DEP0024: REPLServer.prototype.convertToContext()",
"name": "dep0024:_replserver.prototype.converttocontext()",
"desc": "<p>Type: End-of-Life</p>\n<p>The <code>REPLServer.prototype.convertToContext()</code> API is deprecated and should\nnot be used.</p>\n<p><a id=\"DEP0025\"></a></p>\n",
"type": "module",
"displayName": "DEP0024: REPLServer.prototype.convertToContext()"
},
{
"textRaw": "DEP0025: require('sys')",
"name": "dep0025:_require('sys')",
"desc": "<p>Type: Runtime</p>\n<p>The <code>sys</code> module is deprecated. Please use the <a href=\"util.html\"><code>util</code></a> module instead.</p>\n<p><a id=\"DEP0026\"></a></p>\n",
"type": "module",
"displayName": "DEP0025: require('sys')"
},
{
"textRaw": "DEP0026: util.print()",
"name": "dep0026:_util.print()",
"desc": "<p>Type: Runtime</p>\n<p>The <a href=\"util.html#util_util_print_strings\"><code>util.print()</code></a> API is deprecated. Please use <a href=\"console.html#console_console_log_data_args\"><code>console.log()</code></a>\ninstead.</p>\n<p><a id=\"DEP0027\"></a></p>\n",
"type": "module",
"displayName": "DEP0026: util.print()"
},
{
"textRaw": "DEP0027: util.puts()",
"name": "dep0027:_util.puts()",
"desc": "<p>Type: Runtime</p>\n<p>The <a href=\"util.html#util_util_puts_strings\"><code>util.puts()</code></a> API is deprecated. Please use <a href=\"console.html#console_console_log_data_args\"><code>console.log()</code></a> instead.</p>\n<p><a id=\"DEP0028\"></a></p>\n",
"type": "module",
"displayName": "DEP0027: util.puts()"
},
{
"textRaw": "DEP0028: util.debug()",
"name": "dep0028:_util.debug()",
"desc": "<p>Type: Runtime</p>\n<p>The <a href=\"util.html#util_util_debug_string\"><code>util.debug()</code></a> API is deprecated. Please use <a href=\"console.html#console_console_error_data_args\"><code>console.error()</code></a>\ninstead.</p>\n<p><a id=\"DEP0029\"></a></p>\n",
"type": "module",
"displayName": "DEP0028: util.debug()"
},
{
"textRaw": "DEP0029: util.error()",
"name": "dep0029:_util.error()",
"desc": "<p>Type: Runtime</p>\n<p>The <a href=\"util.html#util_util_error_strings\"><code>util.error()</code></a> API is deprecated. Please use <a href=\"console.html#console_console_error_data_args\"><code>console.error()</code></a>\ninstead.</p>\n<p><a id=\"DEP0030\"></a></p>\n",
"type": "module",
"displayName": "DEP0029: util.error()"
},
{
"textRaw": "DEP0030: SlowBuffer",
"name": "dep0030:_slowbuffer",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"buffer.html#buffer_class_slowbuffer\"><code>SlowBuffer</code></a> class is deprecated. Please use\n<a href=\"buffer.html#buffer_class_method_buffer_allocunsafeslow_size\"><code>Buffer.allocUnsafeSlow(size)</code></a> instead.</p>\n<p><a id=\"DEP0031\"></a></p>\n",
"type": "module",
"displayName": "DEP0030: SlowBuffer"
},
{
"textRaw": "DEP0031: ecdh.setPublicKey()",
"name": "dep0031:_ecdh.setpublickey()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"crypto.html#crypto_ecdh_setpublickey_publickey_encoding\"><code>ecdh.setPublicKey()</code></a> method is now deprecated as its inclusion in the\nAPI is not useful.</p>\n<p><a id=\"DEP0032\"></a></p>\n",
"type": "module",
"displayName": "DEP0031: ecdh.setPublicKey()"
},
{
"textRaw": "DEP0032: domain module",
"name": "dep0032:_domain_module",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"domain.html\"><code>domain</code></a> module is deprecated and should not be used.</p>\n<p><a id=\"DEP0033\"></a></p>\n",
"type": "module",
"displayName": "DEP0032: domain module"
},
{
"textRaw": "DEP0033: EventEmitter.listenerCount()",
"name": "dep0033:_eventemitter.listenercount()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"events.html#events_eventemitter_listenercount_emitter_eventname\"><code>EventEmitter.listenerCount(emitter, eventName)</code></a> API is\ndeprecated. Please use <a href=\"events.html#events_emitter_listenercount_eventname\"><code>emitter.listenerCount(eventName)</code></a> instead.</p>\n<p><a id=\"DEP0034\"></a></p>\n",
"type": "module",
"displayName": "DEP0033: EventEmitter.listenerCount()"
},
{
"textRaw": "DEP0034: fs.exists(path, callback)",
"name": "dep0034:_fs.exists(path,_callback)",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"fs.html#fs_fs_exists_path_callback\"><code>fs.exists(path, callback)</code></a> API is deprecated. Please use\n<a href=\"fs.html#fs_fs_stat_path_options_callback\"><code>fs.stat()</code></a> or <a href=\"fs.html#fs_fs_access_path_mode_callback\"><code>fs.access()</code></a> instead.</p>\n<p><a id=\"DEP0035\"></a></p>\n",
"type": "module",
"displayName": "DEP0034: fs.exists(path, callback)"
},
{
"textRaw": "DEP0035: fs.lchmod(path, mode, callback)",
"name": "dep0035:_fs.lchmod(path,_mode,_callback)",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"fs.html#fs_fs_lchmod_path_mode_callback\"><code>fs.lchmod(path, mode, callback)</code></a> API is deprecated.</p>\n<p><a id=\"DEP0036\"></a></p>\n",
"type": "module",
"displayName": "DEP0035: fs.lchmod(path, mode, callback)"
},
{
"textRaw": "DEP0036: fs.lchmodSync(path, mode)",
"name": "dep0036:_fs.lchmodsync(path,_mode)",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"fs.html#fs_fs_lchmodsync_path_mode\"><code>fs.lchmodSync(path, mode)</code></a> API is deprecated.</p>\n<p><a id=\"DEP0039\"></a></p>\n",
"type": "module",
"displayName": "DEP0036: fs.lchmodSync(path, mode)"
},
{
"textRaw": "DEP0039: require.extensions",
"name": "dep0039:_require.extensions",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"modules.html#modules_require_extensions\"><code>require.extensions</code></a> property is deprecated.</p>\n<p><a id=\"DEP0040\"></a></p>\n",
"type": "module",
"displayName": "DEP0039: require.extensions"
},
{
"textRaw": "DEP0040: punycode module",
"name": "dep0040:_punycode_module",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"punycode.html\"><code>punycode</code></a> module is deprecated. Please use a userland alternative\ninstead.</p>\n<p><a id=\"DEP0041\"></a></p>\n",
"type": "module",
"displayName": "DEP0040: punycode module"
},
{
"textRaw": "DEP0041: NODE\\_REPL\\_HISTORY\\_FILE environment variable",
"name": "dep0041:_node\\_repl\\_history\\_file_environment_variable",
"desc": "<p>Type: End-of-Life</p>\n<p>The <code>NODE_REPL_HISTORY_FILE</code> environment variable was removed. Please use\n<code>NODE_REPL_HISTORY</code> instead.</p>\n<p><a id=\"DEP0042\"></a></p>\n",
"type": "module",
"displayName": "DEP0041: NODE\\_REPL\\_HISTORY\\_FILE environment variable"
},
{
"textRaw": "DEP0042: tls.CryptoStream",
"name": "dep0042:_tls.cryptostream",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"tls.html#tls_class_cryptostream\"><code>tls.CryptoStream</code></a> class is deprecated. Please use\n<a href=\"tls.html#tls_class_tls_tlssocket\"><code>tls.TLSSocket</code></a> instead.</p>\n<p><a id=\"DEP0043\"></a></p>\n",
"type": "module",
"displayName": "DEP0042: tls.CryptoStream"
},
{
"textRaw": "DEP0043: tls.SecurePair",
"name": "dep0043:_tls.securepair",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"tls.html#tls_class_securepair\"><code>tls.SecurePair</code></a> class is deprecated. Please use\n<a href=\"tls.html#tls_class_tls_tlssocket\"><code>tls.TLSSocket</code></a> instead.</p>\n<p><a id=\"DEP0044\"></a></p>\n",
"type": "module",
"displayName": "DEP0043: tls.SecurePair"
},
{
"textRaw": "DEP0044: util.isArray()",
"name": "dep0044:_util.isarray()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_isarray_object\"><code>util.isArray()</code></a> API is deprecated. Please use <code>Array.isArray()</code>\ninstead.</p>\n<p><a id=\"DEP0045\"></a></p>\n",
"type": "module",
"displayName": "DEP0044: util.isArray()"
},
{
"textRaw": "DEP0045: util.isBoolean()",
"name": "dep0045:_util.isboolean()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_isboolean_object\"><code>util.isBoolean()</code></a> API is deprecated.</p>\n<p><a id=\"DEP0046\"></a></p>\n",
"type": "module",
"displayName": "DEP0045: util.isBoolean()"
},
{
"textRaw": "DEP0046: util.isBuffer()",
"name": "dep0046:_util.isbuffer()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_isbuffer_object\"><code>util.isBuffer()</code></a> API is deprecated. Please use\n<a href=\"buffer.html#buffer_class_method_buffer_isbuffer_obj\"><code>Buffer.isBuffer()</code></a> instead.</p>\n<p><a id=\"DEP0047\"></a></p>\n",
"type": "module",
"displayName": "DEP0046: util.isBuffer()"
},
{
"textRaw": "DEP0047: util.isDate()",
"name": "dep0047:_util.isdate()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_isdate_object\"><code>util.isDate()</code></a> API is deprecated.</p>\n<p><a id=\"DEP0048\"></a></p>\n",
"type": "module",
"displayName": "DEP0047: util.isDate()"
},
{
"textRaw": "DEP0048: util.isError()",
"name": "dep0048:_util.iserror()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_iserror_object\"><code>util.isError()</code></a> API is deprecated.</p>\n<p><a id=\"DEP0049\"></a></p>\n",
"type": "module",
"displayName": "DEP0048: util.isError()"
},
{
"textRaw": "DEP0049: util.isFunction()",
"name": "dep0049:_util.isfunction()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_isfunction_object\"><code>util.isFunction()</code></a> API is deprecated.</p>\n<p><a id=\"DEP0050\"></a></p>\n",
"type": "module",
"displayName": "DEP0049: util.isFunction()"
},
{
"textRaw": "DEP0050: util.isNull()",
"name": "dep0050:_util.isnull()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_isnull_object\"><code>util.isNull()</code></a> API is deprecated.</p>\n<p><a id=\"DEP0051\"></a></p>\n",
"type": "module",
"displayName": "DEP0050: util.isNull()"
},
{
"textRaw": "DEP0051: util.isNullOrUndefined()",
"name": "dep0051:_util.isnullorundefined()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_isnullorundefined_object\"><code>util.isNullOrUndefined()</code></a> API is deprecated.</p>\n<p><a id=\"DEP0052\"></a></p>\n",
"type": "module",
"displayName": "DEP0051: util.isNullOrUndefined()"
},
{
"textRaw": "DEP0052: util.isNumber()",
"name": "dep0052:_util.isnumber()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_isnumber_object\"><code>util.isNumber()</code></a> API is deprecated.</p>\n<p><a id=\"DEP0053\"></a></p>\n",
"type": "module",
"displayName": "DEP0052: util.isNumber()"
},
{
"textRaw": "DEP0053 util.isObject()",
"name": "dep0053_util.isobject()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_isobject_object\"><code>util.isObject()</code></a> API is deprecated.</p>\n<p><a id=\"DEP0054\"></a></p>\n",
"type": "module",
"displayName": "DEP0053 util.isObject()"
},
{
"textRaw": "DEP0054: util.isPrimitive()",
"name": "dep0054:_util.isprimitive()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_isprimitive_object\"><code>util.isPrimitive()</code></a> API is deprecated.</p>\n<p><a id=\"DEP0055\"></a></p>\n",
"type": "module",
"displayName": "DEP0054: util.isPrimitive()"
},
{
"textRaw": "DEP0055: util.isRegExp()",
"name": "dep0055:_util.isregexp()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_isregexp_object\"><code>util.isRegExp()</code></a> API is deprecated.</p>\n<p><a id=\"DEP0056\"></a></p>\n",
"type": "module",
"displayName": "DEP0055: util.isRegExp()"
},
{
"textRaw": "DEP0056: util.isString()",
"name": "dep0056:_util.isstring()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_isstring_object\"><code>util.isString()</code></a> API is deprecated.</p>\n<p><a id=\"DEP0057\"></a></p>\n",
"type": "module",
"displayName": "DEP0056: util.isString()"
},
{
"textRaw": "DEP0057: util.isSymbol()",
"name": "dep0057:_util.issymbol()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_issymbol_object\"><code>util.isSymbol()</code></a> API is deprecated.</p>\n<p><a id=\"DEP0058\"></a></p>\n",
"type": "module",
"displayName": "DEP0057: util.isSymbol()"
},
{
"textRaw": "DEP0058: util.isUndefined()",
"name": "dep0058:_util.isundefined()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_isundefined_object\"><code>util.isUndefined()</code></a> API is deprecated.</p>\n<p><a id=\"DEP0059\"></a></p>\n",
"type": "module",
"displayName": "DEP0058: util.isUndefined()"
},
{
"textRaw": "DEP0059: util.log()",
"name": "dep0059:_util.log()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_log_string\"><code>util.log()</code></a> API is deprecated.</p>\n<p><a id=\"DEP0060\"></a></p>\n",
"type": "module",
"displayName": "DEP0059: util.log()"
},
{
"textRaw": "DEP0060: util.\\_extend()",
"name": "dep0060:_util.\\_extend()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"util.html#util_util_extend_target_source\"><code>util._extend()</code></a> API is deprecated.</p>\n<p><a id=\"DEP0061\"></a></p>\n",
"type": "module",
"displayName": "DEP0060: util.\\_extend()"
},
{
"textRaw": "DEP0061: fs.SyncWriteStream",
"name": "dep0061:_fs.syncwritestream",
"desc": "<p>Type: End-of-Life</p>\n<p>The <code>fs.SyncWriteStream</code> class was never intended to be a publicly accessible\nAPI and has been removed. No alternative API is available. Please use a userland\nalternative.</p>\n<p><a id=\"DEP0062\"></a></p>\n",
"type": "module",
"displayName": "DEP0061: fs.SyncWriteStream"
},
{
"textRaw": "DEP0062: node --debug",
"name": "dep0062:_node_--debug",
"desc": "<p>Type: Runtime</p>\n<p><code>--debug</code> activates the legacy V8 debugger interface, which was removed as\nof V8 5.8. It is replaced by Inspector which is activated with <code>--inspect</code>\ninstead.</p>\n<p><a id=\"DEP0063\"></a></p>\n",
"type": "module",
"displayName": "DEP0062: node --debug"
},
{
"textRaw": "DEP0063: ServerResponse.prototype.writeHeader()",
"name": "dep0063:_serverresponse.prototype.writeheader()",
"desc": "<p>Type: Documentation-only</p>\n<p>The <code>http</code> module <code>ServerResponse.prototype.writeHeader()</code> API is\ndeprecated. Please use <code>ServerResponse.prototype.writeHead()</code> instead.</p>\n<p>The <code>ServerResponse.prototype.writeHeader()</code> method was never documented as an\nofficially supported API.</p>\n<p><a id=\"DEP0064\"></a></p>\n",
"type": "module",
"displayName": "DEP0063: ServerResponse.prototype.writeHeader()"
},
{
"textRaw": "DEP0064: tls.createSecurePair()",
"name": "dep0064:_tls.createsecurepair()",
"desc": "<p>Type: Runtime</p>\n<p>The <code>tls.createSecurePair()</code> API was deprecated in documentation in Node.js\n0.11.3. Users should use <code>tls.Socket</code> instead.</p>\n<p><a id=\"DEP0065\"></a></p>\n",
"type": "module",
"displayName": "DEP0064: tls.createSecurePair()"
},
{
"textRaw": "DEP0065: repl.REPL_MODE_MAGIC and NODE_REPL_MODE=magic",
"name": "dep0065:_repl.repl_mode_magic_and_node_repl_mode=magic",
"desc": "<p>Type: End-of-Life</p>\n<p>The <code>repl</code> module&#39;s <code>REPL_MODE_MAGIC</code> constant, used for <code>replMode</code> option, has\nbeen removed. Its behavior has been functionally identical to that of\n<code>REPL_MODE_SLOPPY</code> since Node.js 6.0.0, when V8 5.0 was imported. Please use\n<code>REPL_MODE_SLOPPY</code> instead.</p>\n<p>The <code>NODE_REPL_MODE</code> environment variable is used to set the underlying\n<code>replMode</code> of an interactive <code>node</code> session. Its value, <code>magic</code>, is also\nremoved. Please use <code>sloppy</code> instead.</p>\n<p><a id=\"DEP0066\"></a></p>\n",
"type": "module",
"displayName": "DEP0065: repl.REPL_MODE_MAGIC and NODE_REPL_MODE=magic"
},
{
"textRaw": "DEP0066: outgoingMessage.\\_headers, outgoingMessage.\\_headerNames",
"name": "dep0066:_outgoingmessage.\\_headers,_outgoingmessage.\\_headernames",
"desc": "<p>Type: Documentation-only</p>\n<p>The <code>http</code> module <code>outgoingMessage._headers</code> and <code>outgoingMessage._headerNames</code>\nproperties are deprecated. Use one of the public methods\n(e.g. <code>outgoingMessage.getHeader()</code>, <code>outgoingMessage.getHeaders()</code>,\n<code>outgoingMessage.getHeaderNames()</code>, <code>outgoingMessage.hasHeader()</code>,\n<code>outgoingMessage.removeHeader()</code>, <code>outgoingMessage.setHeader()</code>) for working\nwith outgoing headers.</p>\n<p>The <code>outgoingMessage._headers</code> and <code>outgoingMessage._headerNames</code> properties\nwere never documented as officially supported properties.</p>\n<p><a id=\"DEP0067\"></a></p>\n",
"type": "module",
"displayName": "DEP0066: outgoingMessage.\\_headers, outgoingMessage.\\_headerNames"
},
{
"textRaw": "DEP0067: OutgoingMessage.prototype.\\_renderHeaders",
"name": "dep0067:_outgoingmessage.prototype.\\_renderheaders",
"desc": "<p>Type: Documentation-only</p>\n<p>The <code>http</code> module <code>OutgoingMessage.prototype._renderHeaders()</code> API is\ndeprecated.</p>\n<p>The <code>OutgoingMessage.prototype._renderHeaders</code> property was never documented as\nan officially supported API.</p>\n<p><a id=\"DEP0068\"></a></p>\n",
"type": "module",
"displayName": "DEP0067: OutgoingMessage.prototype.\\_renderHeaders"
},
{
"textRaw": "DEP0068: node debug",
"name": "dep0068:_node_debug",
"desc": "<p>Type: Runtime</p>\n<p><code>node debug</code> corresponds to the legacy CLI debugger which has been replaced with\na V8-inspector based CLI debugger available through <code>node inspect</code>.</p>\n<p><a id=\"DEP0069\"></a></p>\n",
"type": "module",
"displayName": "DEP0068: node debug"
},
{
"textRaw": "DEP0069: vm.runInDebugContext(string)",
"name": "dep0069:_vm.runindebugcontext(string)",
"desc": "<p>Type: End-of-Life</p>\n<p>DebugContext has been removed in V8 and is not available in Node.js 10+.</p>\n<p>DebugContext was an experimental API.</p>\n<p><a id=\"DEP0070\"></a></p>\n",
"type": "module",
"displayName": "DEP0069: vm.runInDebugContext(string)"
},
{
"textRaw": "DEP0070: async_hooks.currentId()",
"name": "dep0070:_async_hooks.currentid()",
"desc": "<p>Type: End-of-Life</p>\n<p><code>async_hooks.currentId()</code> was renamed to <code>async_hooks.executionAsyncId()</code> for\nclarity.</p>\n<p>This change was made while <code>async_hooks</code> was an experimental API.</p>\n<p><a id=\"DEP0071\"></a></p>\n",
"type": "module",
"displayName": "DEP0070: async_hooks.currentId()"
},
{
"textRaw": "DEP0071: async_hooks.triggerId()",
"name": "dep0071:_async_hooks.triggerid()",
"desc": "<p>Type: End-of-Life</p>\n<p><code>async_hooks.triggerId()</code> was renamed to <code>async_hooks.triggerAsyncId()</code> for\nclarity.</p>\n<p>This change was made while <code>async_hooks</code> was an experimental API.</p>\n<p><a id=\"DEP0072\"></a></p>\n",
"type": "module",
"displayName": "DEP0071: async_hooks.triggerId()"
},
{
"textRaw": "DEP0072: async_hooks.AsyncResource.triggerId()",
"name": "dep0072:_async_hooks.asyncresource.triggerid()",
"desc": "<p>Type: End-of-Life</p>\n<p><code>async_hooks.AsyncResource.triggerId()</code> was renamed to\n<code>async_hooks.AsyncResource.triggerAsyncId()</code> for clarity.</p>\n<p>This change was made while <code>async_hooks</code> was an experimental API.</p>\n<p><a id=\"DEP0073\"></a></p>\n",
"type": "module",
"displayName": "DEP0072: async_hooks.AsyncResource.triggerId()"
},
{
"textRaw": "DEP0073: Several internal properties of net.Server",
"name": "dep0073:_several_internal_properties_of_net.server",
"desc": "<p>Type: End-of-Life</p>\n<p>Accessing several internal, undocumented properties of <code>net.Server</code> instances\nwith inappropriate names is deprecated.</p>\n<p>As the original API was undocumented and not generally useful for non-internal\ncode, no replacement API is provided.</p>\n<p><a id=\"DEP0074\"></a></p>\n",
"type": "module",
"displayName": "DEP0073: Several internal properties of net.Server"
},
{
"textRaw": "DEP0074: REPLServer.bufferedCommand",
"name": "dep0074:_replserver.bufferedcommand",
"desc": "<p>Type: Runtime</p>\n<p>The <code>REPLServer.bufferedCommand</code> property was deprecated in favor of\n<a href=\"repl.html#repl_replserver_clearbufferedcommand\"><code>REPLServer.clearBufferedCommand()</code></a>.</p>\n<p><a id=\"DEP0075\"></a></p>\n",
"type": "module",
"displayName": "DEP0074: REPLServer.bufferedCommand"
},
{
"textRaw": "DEP0075: REPLServer.parseREPLKeyword()",
"name": "dep0075:_replserver.parsereplkeyword()",
"desc": "<p>Type: Runtime</p>\n<p><code>REPLServer.parseREPLKeyword()</code> was removed from userland visibility.</p>\n<p><a id=\"DEP0076\"></a></p>\n",
"type": "module",
"displayName": "DEP0075: REPLServer.parseREPLKeyword()"
},
{
"textRaw": "DEP0076: tls.parseCertString()",
"name": "dep0076:_tls.parsecertstring()",
"desc": "<p>Type: Runtime</p>\n<p><code>tls.parseCertString()</code> is a trivial parsing helper that was made public by\nmistake. This function can usually be replaced with:</p>\n<pre><code class=\"lang-js\">const querystring = require(&#39;querystring&#39;);\nquerystring.parse(str, &#39;\\n&#39;, &#39;=&#39;);\n</code></pre>\n<p>This function is not completely equivalent to <code>querystring.parse()</code>. One\ndifference is that <code>querystring.parse()</code> does url decoding:</p>\n<pre><code class=\"lang-sh\">&gt; querystring.parse(&#39;%E5%A5%BD=1&#39;, &#39;\\n&#39;, &#39;=&#39;);\n{ &#39;好&#39;: &#39;1&#39; }\n&gt; tls.parseCertString(&#39;%E5%A5%BD=1&#39;);\n{ &#39;%E5%A5%BD&#39;: &#39;1&#39; }\n</code></pre>\n<p><a id=\"DEP0077\"></a></p>\n",
"type": "module",
"displayName": "DEP0076: tls.parseCertString()"
},
{
"textRaw": "DEP0077: Module.\\_debug()",
"name": "dep0077:_module.\\_debug()",
"desc": "<p>Type: Runtime</p>\n<p><code>Module._debug()</code> is deprecated.</p>\n<p>The <code>Module._debug()</code> function was never documented as an officially\nsupported API.</p>\n<p><a id=\"DEP0078\"></a></p>\n",
"type": "module",
"displayName": "DEP0077: Module.\\_debug()"
},
{
"textRaw": "DEP0078: REPLServer.turnOffEditorMode()",
"name": "dep0078:_replserver.turnoffeditormode()",
"desc": "<p>Type: Runtime</p>\n<p><code>REPLServer.turnOffEditorMode()</code> was removed from userland visibility.</p>\n<p><a id=\"DEP0079\"></a></p>\n",
"type": "module",
"displayName": "DEP0078: REPLServer.turnOffEditorMode()"
},
{
"textRaw": "DEP0079: Custom inspection function on Objects via .inspect()",
"name": "dep0079:_custom_inspection_function_on_objects_via_.inspect()",
"desc": "<p>Type: End-of-Life</p>\n<p>Using a property named <code>inspect</code> on an object to specify a custom inspection\nfunction for <a href=\"util.html#util_util_inspect_object_options\"><code>util.inspect()</code></a> is deprecated. Use <a href=\"util.html#util_util_inspect_custom\"><code>util.inspect.custom</code></a>\ninstead. For backward compatibility with Node.js prior to version 6.4.0, both\nmay be specified.</p>\n<p><a id=\"DEP0080\"></a></p>\n",
"type": "module",
"displayName": "DEP0079: Custom inspection function on Objects via .inspect()"
},
{
"textRaw": "DEP0080: path.\\_makeLong()",
"name": "dep0080:_path.\\_makelong()",
"desc": "<p>Type: Documentation-only</p>\n<p>The internal <code>path._makeLong()</code> was not intended for public use. However,\nuserland modules have found it useful. The internal API is deprecated\nand replaced with an identical, public <code>path.toNamespacedPath()</code> method.</p>\n<p><a id=\"DEP0081\"></a></p>\n",
"type": "module",
"displayName": "DEP0080: path.\\_makeLong()"
},
{
"textRaw": "DEP0081: fs.truncate() using a file descriptor",
"name": "dep0081:_fs.truncate()_using_a_file_descriptor",
"desc": "<p>Type: Runtime</p>\n<p><code>fs.truncate()</code> <code>fs.truncateSync()</code> usage with a file descriptor is\ndeprecated. Please use <code>fs.ftruncate()</code> or <code>fs.ftruncateSync()</code> to work with\nfile descriptors.</p>\n<p><a id=\"DEP0082\"></a></p>\n",
"type": "module",
"displayName": "DEP0081: fs.truncate() using a file descriptor"
},
{
"textRaw": "DEP0082: REPLServer.prototype.memory()",
"name": "dep0082:_replserver.prototype.memory()",
"desc": "<p>Type: Runtime</p>\n<p><code>REPLServer.prototype.memory()</code> is only necessary for the internal mechanics of\nthe <code>REPLServer</code> itself. Do not use this function.</p>\n<p><a id=\"DEP0083\"></a></p>\n",
"type": "module",
"displayName": "DEP0082: REPLServer.prototype.memory()"
},
{
"textRaw": "DEP0083: Disabling ECDH by setting ecdhCurve to false",
"name": "dep0083:_disabling_ecdh_by_setting_ecdhcurve_to_false",
"desc": "<p>Type: Runtime</p>\n<p>The <code>ecdhCurve</code> option to <code>tls.createSecureContext()</code> and <code>tls.TLSSocket</code> could\nbe set to <code>false</code> to disable ECDH entirely on the server only. This mode is\ndeprecated in preparation for migrating to OpenSSL 1.1.0 and consistency with\nthe client. Use the <code>ciphers</code> parameter instead.</p>\n<p><a id=\"DEP0084\"></a></p>\n",
"type": "module",
"displayName": "DEP0083: Disabling ECDH by setting ecdhCurve to false"
},
{
"textRaw": "DEP0084: requiring bundled internal dependencies",
"name": "dep0084:_requiring_bundled_internal_dependencies",
"desc": "<p>Type: Runtime</p>\n<p>Since Node.js versions 4.4.0 and 5.2.0, several modules only intended for\ninternal usage are mistakenly exposed to user code through <code>require()</code>. These\nmodules are:</p>\n<ul>\n<li><code>v8/tools/codemap</code></li>\n<li><code>v8/tools/consarray</code></li>\n<li><code>v8/tools/csvparser</code></li>\n<li><code>v8/tools/logreader</code></li>\n<li><code>v8/tools/profile_view</code></li>\n<li><code>v8/tools/profile</code></li>\n<li><code>v8/tools/SourceMap</code></li>\n<li><code>v8/tools/splaytree</code></li>\n<li><code>v8/tools/tickprocessor-driver</code></li>\n<li><code>v8/tools/tickprocessor</code></li>\n<li><code>node-inspect/lib/_inspect</code> (from 7.6.0)</li>\n<li><code>node-inspect/lib/internal/inspect_client</code> (from 7.6.0)</li>\n<li><code>node-inspect/lib/internal/inspect_repl</code> (from 7.6.0)</li>\n</ul>\n<p>The <code>v8/*</code> modules do not have any exports, and if not imported in a specific\norder would in fact throw errors. As such there are virtually no legitimate use\ncases for importing them through <code>require()</code>.</p>\n<p>On the other hand, <code>node-inspect</code> may be installed locally through a package\nmanager, as it is published on the npm registry under the same name. No source\ncode modification is necessary if that is done.</p>\n<p><a id=\"DEP0085\"></a></p>\n",
"type": "module",
"displayName": "DEP0084: requiring bundled internal dependencies"
},
{
"textRaw": "DEP0085: AsyncHooks Sensitive API",
"name": "dep0085:_asynchooks_sensitive_api",
"desc": "<p>Type: End-of-Life</p>\n<p>The AsyncHooks Sensitive API was never documented and had various minor issues.\n(See <a href=\"https://github.com/nodejs/node/issues/15572\">https://github.com/nodejs/node/issues/15572</a>.) Use the <code>AsyncResource</code>\nAPI instead.</p>\n<p><a id=\"DEP0086\"></a></p>\n",
"type": "module",
"displayName": "DEP0085: AsyncHooks Sensitive API"
},
{
"textRaw": "DEP0086: Remove runInAsyncIdScope",
"name": "dep0086:_remove_runinasyncidscope",
"desc": "<p>Type: End-of-Life</p>\n<p><code>runInAsyncIdScope</code> doesn&#39;t emit the <code>&#39;before&#39;</code> or <code>&#39;after&#39;</code> event and can thus\ncause a lot of issues. See <a href=\"https://github.com/nodejs/node/issues/14328\">https://github.com/nodejs/node/issues/14328</a> for more\ndetails.</p>\n<p><a id=\"DEP0089\"></a></p>\n",
"type": "module",
"displayName": "DEP0086: Remove runInAsyncIdScope"
},
{
"textRaw": "DEP0089: require('assert')",
"name": "dep0089:_require('assert')",
"desc": "<p>Type: Documentation-only</p>\n<p>Importing assert directly is not recommended as the exposed functions will use\nloose equality checks. Use <code>require(&#39;assert&#39;).strict</code> instead. The API is the\nsame as the legacy assert but it will always use strict equality checks.</p>\n<p><a id=\"DEP0090\"></a></p>\n",
"type": "module",
"displayName": "DEP0089: require('assert')"
},
{
"textRaw": "DEP0090: Invalid GCM authentication tag lengths",
"name": "dep0090:_invalid_gcm_authentication_tag_lengths",
"desc": "<p>Type: End-of-Life</p>\n<p>Node.js used to support all GCM authentication tag lengths which are accepted by\nOpenSSL when calling <a href=\"crypto.html#crypto_decipher_setauthtag_buffer\"><code>decipher.setAuthTag()</code></a>. Beginning with node REPLACEME,\nonly authentication tag lengths of 128, 120, 112, 104, 96, 64, and 32 bits are\nallowed. Authentication tags whose length is not included in this list are\nconsidered invalid in compliance with <a href=\"http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf\">NIST SP 800-38D</a>.</p>\n<p><a id=\"DEP0091\"></a></p>\n",
"type": "module",
"displayName": "DEP0090: Invalid GCM authentication tag lengths"
},
{
"textRaw": "DEP0091: crypto.DEFAULT_ENCODING",
"name": "dep0091:_crypto.default_encoding",
"desc": "<p>Type: Runtime</p>\n<p>The <a href=\"crypto.html#crypto_crypto_default_encoding\"><code>crypto.DEFAULT_ENCODING</code></a> property is deprecated.</p>\n<p><a id=\"DEP0092\"></a></p>\n",
"type": "module",
"displayName": "DEP0091: crypto.DEFAULT_ENCODING"
},
{
"textRaw": "DEP0092: Top-level `this` bound to `module.exports`",
"name": "dep0092:_top-level_`this`_bound_to_`module.exports`",
"desc": "<p>Type: Documentation-only</p>\n<p>Assigning properties to the top-level <code>this</code> as an alternative\nto <code>module.exports</code> is deprecated. Developers should use <code>exports</code>\nor <code>module.exports</code> instead.</p>\n<p><a id=\"DEP0093\"></a></p>\n",
"type": "module",
"displayName": "DEP0092: Top-level `this` bound to `module.exports`"
},
{
"textRaw": "DEP0093: crypto.fips is deprecated and replaced.",
"name": "dep0093:_crypto.fips_is_deprecated_and_replaced.",
"desc": "<p>Type: Documentation-only</p>\n<p>The <a href=\"crypto.html#crypto_crypto_fips\"><code>crypto.fips</code></a> property is deprecated. Please use <code>crypto.setFips()</code>\nand <code>crypto.getFips()</code> instead.</p>\n<p><a id=\"DEP0094\"></a></p>\n",
"type": "module",
"displayName": "DEP0093: crypto.fips is deprecated and replaced."
},
{
"textRaw": "DEP0094: Using `assert.fail()` with more than one argument.",
"name": "dep0094:_using_`assert.fail()`_with_more_than_one_argument.",
"desc": "<p>Type: Runtime</p>\n<p>Using <code>assert.fail()</code> with more than one argument is deprecated. Use\n<code>assert.fail()</code> with only one argument or use a different <code>assert</code> module\nmethod.</p>\n<p><a id=\"DEP0095\"></a></p>\n",
"type": "module",
"displayName": "DEP0094: Using `assert.fail()` with more than one argument."
},
{
"textRaw": "DEP0095: timers.enroll()",
"name": "dep0095:_timers.enroll()",
"desc": "<p>Type: Runtime</p>\n<p><code>timers.enroll()</code> is deprecated. Please use the publicly documented\n<a href=\"timers.html#timers_settimeout_callback_delay_args\"><code>setTimeout()</code></a> or <a href=\"timers.html#timers_setinterval_callback_delay_args\"><code>setInterval()</code></a> instead.</p>\n<p><a id=\"DEP0096\"></a></p>\n",
"type": "module",
"displayName": "DEP0095: timers.enroll()"
},
{
"textRaw": "DEP0096: timers.unenroll()",
"name": "dep0096:_timers.unenroll()",
"desc": "<p>Type: Runtime</p>\n<p><code>timers.unenroll()</code> is deprecated. Please use the publicly documented\n<a href=\"timers.html#timers_cleartimeout_timeout\"><code>clearTimeout()</code></a> or <a href=\"timers.html#timers_clearinterval_timeout\"><code>clearInterval()</code></a> instead.</p>\n<p><a id=\"DEP0097\"></a></p>\n",
"type": "module",
"displayName": "DEP0096: timers.unenroll()"
},
{
"textRaw": "DEP0097: MakeCallback with domain property",
"name": "dep0097:_makecallback_with_domain_property",
"desc": "<p>Type: Runtime</p>\n<p>Users of <code>MakeCallback</code> that add the <code>domain</code> property to carry context,\nshould start using the <code>async_context</code> variant of <code>MakeCallback</code> or\n<code>CallbackScope</code>, or the high-level <code>AsyncResource</code> class.</p>\n<p><a id=\"DEP0098\"></a></p>\n",
"type": "module",
"displayName": "DEP0097: MakeCallback with domain property"
},
{
"textRaw": "DEP0098: AsyncHooks Embedder AsyncResource.emitBefore and AsyncResource.emitAfter APIs",
"name": "dep0098:_asynchooks_embedder_asyncresource.emitbefore_and_asyncresource.emitafter_apis",
"desc": "<p>Type: Runtime</p>\n<p>The embedded API provided by AsyncHooks exposes <code>.emitBefore()</code> and\n<code>.emitAfter()</code> methods which are very easy to use incorrectly which can lead\nto unrecoverable errors.</p>\n<p>Use <a href=\"async_hooks.html#async_hooks_asyncresource_runinasyncscope_fn_thisarg_args\"><code>asyncResource.runInAsyncScope()</code></a> API instead which provides a much\nsafer, and more convenient, alternative. See\n<a href=\"https://github.com/nodejs/node/pull/18513\">https://github.com/nodejs/node/pull/18513</a> for more details.</p>\n<p><a id=\"DEP0099\"></a></p>\n",
"type": "module",
"displayName": "DEP0098: AsyncHooks Embedder AsyncResource.emitBefore and AsyncResource.emitAfter APIs"
},
{
"textRaw": "DEP0099: async context-unaware node::MakeCallback C++ APIs",
"name": "dep0099:_async_context-unaware_node::makecallback_c++_apis",
"desc": "<p>Type: Compile-time</p>\n<p>Certain versions of <code>node::MakeCallback</code> APIs available to native modules are\ndeprecated. Please use the versions of the API that accept an <code>async_context</code>\nparameter.</p>\n<p><a id=\"DEP0100\"></a></p>\n",
"type": "module",
"displayName": "DEP0099: async context-unaware node::MakeCallback C++ APIs"
},
{
"textRaw": "DEP0100: process.assert()",
"name": "dep0100:_process.assert()",
"desc": "<p>Type: Runtime</p>\n<p><code>process.assert()</code> is deprecated. Please use the <a href=\"assert.html\"><code>assert</code></a> module instead.</p>\n<p>This was never a documented feature.</p>\n<p><a id=\"DEP0101\"></a></p>\n",
"type": "module",
"displayName": "DEP0100: process.assert()"
},
{
"textRaw": "DEP0101: --with-lttng",
"name": "dep0101:_--with-lttng",
"desc": "<p>Type: End-of-Life</p>\n<p>The <code>--with-lttng</code> compile-time option has been removed.</p>\n<p><a id=\"DEP0102\"></a></p>\n",
"type": "module",
"displayName": "DEP0101: --with-lttng"
},
{
"textRaw": "DEP0102: Using `noAssert` in Buffer#(read|write) operations.",
"name": "dep0102:_using_`noassert`_in_buffer#(read|write)_operations.",
"desc": "<p>Type: End-of-Life</p>\n<p>Using the <code>noAssert</code> argument has no functionality anymore. All input is going\nto be verified, no matter if it is set to true or not. Skipping the verification\ncould lead to hard to find errors and crashes.</p>\n<p><a id=\"DEP0103\"></a></p>\n",
"type": "module",
"displayName": "DEP0102: Using `noAssert` in Buffer#(read|write) operations."
},
{
"textRaw": "DEP0103: process.binding('util').is[...] typechecks",
"name": "dep0103:_process.binding('util').is[...]_typechecks",
"desc": "<p>Type: Documentation-only (supports <a href=\"cli.html#cli_pending_deprecation\"><code>--pending-deprecation</code></a>)</p>\n<p>Using <code>process.binding()</code> in general should be avoided. The type checking\nmethods in particular can be replaced by using <a href=\"util.html#util_util_types\"><code>util.types</code></a>.</p>\n<p><a id=\"DEP0104\"></a></p>\n",
"type": "module",
"displayName": "DEP0103: process.binding('util').is[...] typechecks"
},
{
"textRaw": "DEP0104: process.env string coercion",
"name": "dep0104:_process.env_string_coercion",
"desc": "<p>Type: Documentation-only (supports <a href=\"cli.html#cli_pending_deprecation\"><code>--pending-deprecation</code></a>)</p>\n<p>When assigning a non-string property to <a href=\"process.html#process_process_env\"><code>process.env</code></a>, the assigned value is\nimplicitly converted to a string. This behavior is deprecated if the assigned\nvalue is not a string, boolean, or number. In the future, such assignment may\nresult in a thrown error. Please convert the property to a string before\nassigning it to <code>process.env</code>.</p>\n<p><a id=\"DEP0105\"></a></p>\n",
"type": "module",
"displayName": "DEP0104: process.env string coercion"
},
{
"textRaw": "DEP0105: decipher.finaltol",
"name": "dep0105:_decipher.finaltol",
"desc": "<p>Type: End-of-Life</p>\n<p><code>decipher.finaltol()</code> has never been documented and was an alias for\n<a href=\"crypto.html#crypto_decipher_final_outputencoding\"><code>decipher.final()</code></a>. This API has been removed, and it is recommended to use\n<a href=\"crypto.html#crypto_decipher_final_outputencoding\"><code>decipher.final()</code></a> instead.</p>\n<p><a id=\"DEP0106\"></a></p>\n",
"type": "module",
"displayName": "DEP0105: decipher.finaltol"
},
{
"textRaw": "DEP0106: crypto.createCipher and crypto.createDecipher",
"name": "dep0106:_crypto.createcipher_and_crypto.createdecipher",
"desc": "<p>Type: Documentation-only</p>\n<p>Using <a href=\"crypto.html#crypto_crypto_createcipher_algorithm_password_options\"><code>crypto.createCipher()</code></a> and <a href=\"crypto.html#crypto_crypto_createdecipher_algorithm_password_options\"><code>crypto.createDecipher()</code></a> should be\navoided as they use a weak key derivation function (MD5 with no salt) and static\ninitialization vectors. It is recommended to derive a key using\n<a href=\"crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback\"><code>crypto.pbkdf2()</code></a> and to use <a href=\"crypto.html#crypto_crypto_createcipheriv_algorithm_key_iv_options\"><code>crypto.createCipheriv()</code></a> and\n<a href=\"crypto.html#crypto_crypto_createdecipheriv_algorithm_key_iv_options\"><code>crypto.createDecipheriv()</code></a> to obtain the <a href=\"crypto.html#crypto_class_cipher\"><code>Cipher</code></a> and <a href=\"crypto.html#crypto_class_decipher\"><code>Decipher</code></a>\nobjects respectively.</p>\n<p><a id=\"DEP0107\"></a></p>\n",
"type": "module",
"displayName": "DEP0106: crypto.createCipher and crypto.createDecipher"
},
{
"textRaw": "DEP0107: tls.convertNPNProtocols()",
"name": "dep0107:_tls.convertnpnprotocols()",
"desc": "<p>Type: End-of-Life</p>\n<p>This was an undocumented helper function not intended for use outside Node.js\ncore and obsoleted by the removal of NPN (Next Protocol Negotiation) support.</p>\n<p><a id=\"DEP0108\"></a></p>\n",
"type": "module",
"displayName": "DEP0107: tls.convertNPNProtocols()"
},
{
"textRaw": "DEP0108: zlib.bytesRead",
"name": "dep0108:_zlib.bytesread",
"desc": "<p>Type: Documentation-only</p>\n<p>Deprecated alias for <a href=\"zlib.html#zlib_zlib_byteswritten\"><code>zlib.bytesWritten</code></a>. This original name was chosen\nbecause it also made sense to interpret the value as the number of bytes\nread by the engine, but is inconsistent with other streams in Node.js that\nexpose values under these names.</p>\n<p><a id=\"DEP0109\"></a></p>\n",
"type": "module",
"displayName": "DEP0108: zlib.bytesRead"
},
{
"textRaw": "DEP0109: http, https, and tls support for invalid URLs",
"name": "dep0109:_http,_https,_and_tls_support_for_invalid_urls",
"desc": "<p>Type: Runtime</p>\n<p>Some previously supported (but strictly invalid) URLs were accepted through the\n<a href=\"http.html#http_http_request_options_callback\"><code>http.request()</code></a>, <a href=\"http.html#http_http_get_options_callback\"><code>http.get()</code></a>, <a href=\"https.html#https_https_request_options_callback\"><code>https.request()</code></a>,\n<a href=\"https.html#https_https_get_options_callback\"><code>https.get()</code></a>, and <a href=\"tls.html#tls_tls_checkserveridentity_hostname_cert\"><code>tls.checkServerIdentity()</code></a> APIs because those were\naccepted by the legacy <code>url.parse()</code> API. The mentioned APIs now use the WHATWG\nURL parser that requires strictly valid URLs. Passing an invalid URL is\ndeprecated and support will be removed in the future.</p>\n<p><a id=\"DEP0110\"></a></p>\n",
"type": "module",
"displayName": "DEP0109: http, https, and tls support for invalid URLs"
},
{
"textRaw": "DEP0110: vm.Script cached data",
"name": "dep0110:_vm.script_cached_data",
"desc": "<p>Type: Documentation-only</p>\n<p>The option <code>produceCachedData</code> has been deprecated. Use\n<a href=\"vm.html#vm_script_createcacheddata\"><code>script.createCachedData()</code></a> instead.</p>\n",
"type": "module",
"displayName": "DEP0110: vm.Script cached data"
}
],
"type": "misc",
"displayName": "List of Deprecated APIs"
}
]
},
{
"textRaw": "ECMAScript Modules",
"name": "esm",
"introduced_in": "v8.5.0",
"type": "misc",
"stability": 1,
"stabilityText": "Experimental",
"desc": "<p>Node.js contains support for ES Modules based upon the\n<a href=\"https://github.com/nodejs/node-eps/blob/master/002-es-modules.md\">Node.js EP for ES Modules</a>.</p>\n<p>Not all features of the EP are complete and will be landing as both VM support\nand implementation is ready. Error messages are still being polished.</p>\n",
"miscs": [
{
"textRaw": "Enabling",
"name": "Enabling",
"type": "misc",
"desc": "<p>The <code>--experimental-modules</code> flag can be used to enable features for loading\nESM modules.</p>\n<p>Once this has been set, files ending with <code>.mjs</code> will be able to be loaded\nas ES Modules.</p>\n<pre><code class=\"lang-sh\">node --experimental-modules my-app.mjs\n</code></pre>\n"
},
{
"textRaw": "Features",
"name": "Features",
"type": "misc",
"miscs": [
{
"textRaw": "Supported",
"name": "supported",
"desc": "<p>Only the CLI argument for the main entry point to the program can be an entry\npoint into an ESM graph. Dynamic import can also be used to create entry points\ninto ESM graphs at runtime.</p>\n",
"properties": [
{
"textRaw": "`meta` {Object} ",
"type": "Object",
"name": "meta",
"desc": "<p>The <code>import.meta</code> metaproperty is an <code>Object</code> that contains the following\nproperty:</p>\n<ul>\n<li><code>url</code> {string} The absolute <code>file:</code> URL of the module.</li>\n</ul>\n"
}
],
"type": "misc",
"displayName": "Supported"
},
{
"textRaw": "Unsupported",
"name": "unsupported",
"desc": "<table>\n<thead>\n<tr>\n<th>Feature</th>\n<th>Reason</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>require(&#39;./foo.mjs&#39;)</code></td>\n<td>ES Modules have differing resolution and timing, use dynamic import</td>\n</tr>\n</tbody>\n</table>\n",
"type": "misc",
"displayName": "Unsupported"
}
]
},
{
"textRaw": "Notable differences between `import` and `require`",
"name": "notable_differences_between_`import`_and_`require`",
"modules": [
{
"textRaw": "No NODE_PATH",
"name": "no_node_path",
"desc": "<p><code>NODE_PATH</code> is not part of resolving <code>import</code> specifiers. Please use symlinks\nif this behavior is desired.</p>\n",
"type": "module",
"displayName": "No NODE_PATH"
},
{
"textRaw": "No `require.extensions`",
"name": "no_`require.extensions`",
"desc": "<p><code>require.extensions</code> is not used by <code>import</code>. The expectation is that loader\nhooks can provide this workflow in the future.</p>\n",
"type": "module",
"displayName": "No `require.extensions`"
},
{
"textRaw": "No `require.cache`",
"name": "no_`require.cache`",
"desc": "<p><code>require.cache</code> is not used by <code>import</code>. It has a separate cache.</p>\n",
"type": "module",
"displayName": "No `require.cache`"
},
{
"textRaw": "URL based paths",
"name": "url_based_paths",
"desc": "<p>ESM are resolved and cached based upon <a href=\"https://url.spec.whatwg.org/\">URL</a>\nsemantics. This means that files containing special characters such as <code>#</code> and\n<code>?</code> need to be escaped.</p>\n<p>Modules will be loaded multiple times if the <code>import</code> specifier used to resolve\nthem have a different query or fragment.</p>\n<pre><code class=\"lang-js\">import &#39;./foo?query=1&#39;; // loads ./foo with query of &quot;?query=1&quot;\nimport &#39;./foo?query=2&#39;; // loads ./foo with query of &quot;?query=2&quot;\n</code></pre>\n<p>For now, only modules using the <code>file:</code> protocol can be loaded.</p>\n",
"type": "module",
"displayName": "URL based paths"
}
],
"type": "misc",
"displayName": "Notable differences between `import` and `require`"
},
{
"textRaw": "Interop with existing modules",
"name": "interop_with_existing_modules",
"desc": "<p>All CommonJS, JSON, and C++ modules can be used with <code>import</code>.</p>\n<p>Modules loaded this way will only be loaded once, even if their query\nor fragment string differs between <code>import</code> statements.</p>\n<p>When loaded via <code>import</code> these modules will provide a single <code>default</code> export\nrepresenting the value of <code>module.exports</code> at the time they finished evaluating.</p>\n<pre><code class=\"lang-js\">// foo.js\nmodule.exports = { one: 1 };\n\n// bar.js\nimport foo from &#39;./foo.js&#39;;\nfoo.one === 1; // true\n</code></pre>\n<p>Builtin modules will provide named exports of their public API, as well as a\ndefault export which can be used for, among other things, modifying the named\nexports. Named exports of builtin modules are updated when the corresponding\nexports property is accessed, redefined, or deleted.</p>\n<pre><code class=\"lang-js\">import EventEmitter from &#39;events&#39;;\nconst e = new EventEmitter();\n</code></pre>\n<pre><code class=\"lang-js\">import { readFile } from &#39;fs&#39;;\nreadFile(&#39;./foo.txt&#39;, (err, source) =&gt; {\n if (err) {\n console.error(err);\n } else {\n console.log(source);\n }\n});\n</code></pre>\n<pre><code class=\"lang-js\">import fs, { readFileSync } from &#39;fs&#39;;\n\nfs.readFileSync = () =&gt; Buffer.from(&#39;Hello, ESM&#39;);\n\nfs.readFileSync === readFileSync;\n</code></pre>\n",
"type": "misc",
"displayName": "Interop with existing modules"
},
{
"textRaw": "Loader hooks",
"name": "Loader hooks",
"type": "misc",
"desc": "<p>To customize the default module resolution, loader hooks can optionally be\nprovided via a <code>--loader ./loader-name.mjs</code> argument to Node.js.</p>\n<p>When hooks are used they only apply to ES module loading and not to any\nCommonJS modules loaded.</p>\n",
"miscs": [
{
"textRaw": "Resolve hook",
"name": "resolve_hook",
"desc": "<p>The resolve hook returns the resolved file URL and module format for a\ngiven module specifier and parent file URL:</p>\n<pre><code class=\"lang-js\">const baseURL = new URL(&#39;file://&#39;);\nbaseURL.pathname = `${process.cwd()}/`;\n\nexport async function resolve(specifier,\n parentModuleURL = baseURL,\n defaultResolver) {\n return {\n url: new URL(specifier, parentModuleURL).href,\n format: &#39;esm&#39;\n };\n}\n</code></pre>\n<p>The <code>parentModuleURL</code> is provided as <code>undefined</code> when performing main Node.js\nload itself.</p>\n<p>The default Node.js ES module resolution function is provided as a third\nargument to the resolver for easy compatibility workflows.</p>\n<p>In addition to returning the resolved file URL value, the resolve hook also\nreturns a <code>format</code> property specifying the module format of the resolved\nmodule. This can be one of the following:</p>\n<table>\n<thead>\n<tr>\n<th><code>format</code></th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>&#39;esm&#39;</code></td>\n<td>Load a standard JavaScript module</td>\n</tr>\n<tr>\n<td><code>&#39;cjs&#39;</code></td>\n<td>Load a node-style CommonJS module</td>\n</tr>\n<tr>\n<td><code>&#39;builtin&#39;</code></td>\n<td>Load a node builtin CommonJS module</td>\n</tr>\n<tr>\n<td><code>&#39;json&#39;</code></td>\n<td>Load a JSON file</td>\n</tr>\n<tr>\n<td><code>&#39;addon&#39;</code></td>\n<td>Load a <a href=\"addons.html\">C++ Addon</a></td>\n</tr>\n<tr>\n<td><code>&#39;dynamic&#39;</code></td>\n<td>Use a <a href=\"#esm_dynamic_instantiate_hook\">dynamic instantiate hook</a></td>\n</tr>\n</tbody>\n</table>\n<p>For example, a dummy loader to load JavaScript restricted to browser resolution\nrules with only JS file extension and Node.js builtin modules support could\nbe written:</p>\n<pre><code class=\"lang-js\">import path from &#39;path&#39;;\nimport process from &#39;process&#39;;\nimport Module from &#39;module&#39;;\n\nconst builtins = Module.builtinModules;\nconst JS_EXTENSIONS = new Set([&#39;.js&#39;, &#39;.mjs&#39;]);\n\nconst baseURL = new URL(&#39;file://&#39;);\nbaseURL.pathname = `${process.cwd()}/`;\n\nexport function resolve(specifier, parentModuleURL = baseURL, defaultResolve) {\n if (builtins.includes(specifier)) {\n return {\n url: specifier,\n format: &#39;builtin&#39;\n };\n }\n if (/^\\.{0,2}[/]/.test(specifier) !== true &amp;&amp; !specifier.startsWith(&#39;file:&#39;)) {\n // For node_modules support:\n // return defaultResolve(specifier, parentModuleURL);\n throw new Error(\n `imports must begin with &#39;/&#39;, &#39;./&#39;, or &#39;../&#39;; &#39;${specifier}&#39; does not`);\n }\n const resolved = new URL(specifier, parentModuleURL);\n const ext = path.extname(resolved.pathname);\n if (!JS_EXTENSIONS.has(ext)) {\n throw new Error(\n `Cannot load file with non-JavaScript file extension ${ext}.`);\n }\n return {\n url: resolved.href,\n format: &#39;esm&#39;\n };\n}\n</code></pre>\n<p>With this loader, running:</p>\n<pre><code class=\"lang-console\">NODE_OPTIONS=&#39;--experimental-modules --loader ./custom-loader.mjs&#39; node x.js\n</code></pre>\n<p>would load the module <code>x.js</code> as an ES module with relative resolution support\n(with <code>node_modules</code> loading skipped in this example).</p>\n",
"type": "misc",
"displayName": "Resolve hook"
},
{
"textRaw": "Dynamic instantiate hook",
"name": "dynamic_instantiate_hook",
"desc": "<p>To create a custom dynamic module that doesn&#39;t correspond to one of the\nexisting <code>format</code> interpretations, the <code>dynamicInstantiate</code> hook can be used.\nThis hook is called only for modules that return <code>format: &#39;dynamic&#39;</code> from\nthe <code>resolve</code> hook.</p>\n<pre><code class=\"lang-js\">export async function dynamicInstantiate(url) {\n return {\n exports: [&#39;customExportName&#39;],\n execute: (exports) =&gt; {\n // get and set functions provided for pre-allocated export names\n exports.customExportName.set(&#39;value&#39;);\n }\n };\n}\n</code></pre>\n<p>With the list of module exports provided upfront, the <code>execute</code> function will\nthen be called at the exact point of module evaluation order for that module\nin the import tree.</p>\n",
"type": "misc",
"displayName": "Dynamic instantiate hook"
}
]
}
]
},
{
"textRaw": "Errors",
"name": "Errors",
"introduced_in": "v4.0.0",
"type": "misc",
"desc": "<p>Applications running in Node.js will generally experience four categories of\nerrors:</p>\n<ul>\n<li>Standard JavaScript errors such as {EvalError}, {SyntaxError}, {RangeError},\n{ReferenceError}, {TypeError}, and {URIError}.</li>\n<li>System errors triggered by underlying operating system constraints such\nas attempting to open a file that does not exist or attempting to send data\nover a closed socket.</li>\n<li>User-specified errors triggered by application code.</li>\n<li><code>AssertionError</code>s are a special class of error that can be triggered when\nNode.js detects an exceptional logic violation that should never occur. These\nare raised typically by the <code>assert</code> module.</li>\n</ul>\n<p>All JavaScript and System errors raised by Node.js inherit from, or are\ninstances of, the standard JavaScript {Error} class and are guaranteed\nto provide <em>at least</em> the properties available on that class.</p>\n",
"miscs": [
{
"textRaw": "Error Propagation and Interception",
"name": "Error Propagation and Interception",
"type": "misc",
"desc": "<p>Node.js supports several mechanisms for propagating and handling errors that\noccur while an application is running. How these errors are reported and\nhandled depends entirely on the type of <code>Error</code> and the style of the API that is\ncalled.</p>\n<p>All JavaScript errors are handled as exceptions that <em>immediately</em> generate\nand throw an error using the standard JavaScript <code>throw</code> mechanism. These\nare handled using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch\"><code>try…catch</code> construct</a> provided by the\nJavaScript language.</p>\n<pre><code class=\"lang-js\">// Throws with a ReferenceError because z is undefined\ntry {\n const m = 1;\n const n = m + z;\n} catch (err) {\n // Handle the error here.\n}\n</code></pre>\n<p>Any use of the JavaScript <code>throw</code> mechanism will raise an exception that\n<em>must</em> be handled using <code>try…catch</code> or the Node.js process will exit\nimmediately.</p>\n<p>With few exceptions, <em>Synchronous</em> APIs (any blocking method that does not\naccept a <code>callback</code> function, such as <a href=\"fs.html#fs_fs_readfilesync_path_options\"><code>fs.readFileSync</code></a>), will use <code>throw</code>\nto report errors.</p>\n<p>Errors that occur within <em>Asynchronous APIs</em> may be reported in multiple ways:</p>\n<ul>\n<li>Most asynchronous methods that accept a <code>callback</code> function will accept an\n<code>Error</code> object passed as the first argument to that function. If that first\nargument is not <code>null</code> and is an instance of <code>Error</code>, then an error occurred\nthat should be handled.</li>\n</ul>\n<!-- eslint-disable no-useless-return -->\n<pre><code class=\"lang-js\"> const fs = require(&#39;fs&#39;);\n fs.readFile(&#39;a file that does not exist&#39;, (err, data) =&gt; {\n if (err) {\n console.error(&#39;There was an error reading the file!&#39;, err);\n return;\n }\n // Otherwise handle the data\n });\n</code></pre>\n<ul>\n<li><p>When an asynchronous method is called on an object that is an\n<a href=\"events.html#events_class_eventemitter\"><code>EventEmitter</code></a>, errors can be routed to that object&#39;s <code>&#39;error&#39;</code> event.</p>\n<pre><code class=\"lang-js\">const net = require(&#39;net&#39;);\nconst connection = net.connect(&#39;localhost&#39;);\n\n// Adding an &#39;error&#39; event handler to a stream:\nconnection.on(&#39;error&#39;, (err) =&gt; {\n // If the connection is reset by the server, or if it can&#39;t\n // connect at all, or on any sort of error encountered by\n // the connection, the error will be sent here.\n console.error(err);\n});\n\nconnection.pipe(process.stdout);\n</code></pre>\n</li>\n<li><p>A handful of typically asynchronous methods in the Node.js API may still\nuse the <code>throw</code> mechanism to raise exceptions that must be handled using\n<code>try…catch</code>. There is no comprehensive list of such methods; please\nrefer to the documentation of each method to determine the appropriate\nerror handling mechanism required.</p>\n</li>\n</ul>\n<p>The use of the <code>&#39;error&#39;</code> event mechanism is most common for <a href=\"stream.html\">stream-based</a>\nand <a href=\"events.html#events_class_eventemitter\">event emitter-based</a> APIs, which themselves represent a series of\nasynchronous operations over time (as opposed to a single operation that may\npass or fail).</p>\n<p>For <em>all</em> <a href=\"events.html#events_class_eventemitter\"><code>EventEmitter</code></a> objects, if an <code>&#39;error&#39;</code> event handler is not\nprovided, the error will be thrown, causing the Node.js process to report an\nuncaught exception and crash unless either: The <a href=\"domain.html\"><code>domain</code></a> module is\nused appropriately or a handler has been registered for the\n<a href=\"process.html#process_event_uncaughtexception\"><code>&#39;uncaughtException&#39;</code></a> event.</p>\n<pre><code class=\"lang-js\">const EventEmitter = require(&#39;events&#39;);\nconst ee = new EventEmitter();\n\nsetImmediate(() =&gt; {\n // This will crash the process because no &#39;error&#39; event\n // handler has been added.\n ee.emit(&#39;error&#39;, new Error(&#39;This will crash&#39;));\n});\n</code></pre>\n<p>Errors generated in this way <em>cannot</em> be intercepted using <code>try…catch</code> as\nthey are thrown <em>after</em> the calling code has already exited.</p>\n<p>Developers must refer to the documentation for each method to determine\nexactly how errors raised by those methods are propagated.</p>\n",
"miscs": [
{
"textRaw": "Error-first callbacks",
"name": "Error-first callbacks",
"type": "misc",
"desc": "<p>Most asynchronous methods exposed by the Node.js core API follow an idiomatic\npattern referred to as an <em>error-first callback</em> (sometimes referred to as\na <em>Node.js style callback</em>). With this pattern, a callback function is passed\nto the method as an argument. When the operation either completes or an error\nis raised, the callback function is called with\nthe <code>Error</code> object (if any) passed as the first argument. If no error was\nraised, the first argument will be passed as <code>null</code>.</p>\n<pre><code class=\"lang-js\">const fs = require(&#39;fs&#39;);\n\nfunction errorFirstCallback(err, data) {\n if (err) {\n console.error(&#39;There was an error&#39;, err);\n return;\n }\n console.log(data);\n}\n\nfs.readFile(&#39;/some/file/that/does-not-exist&#39;, errorFirstCallback);\nfs.readFile(&#39;/some/file/that/does-exist&#39;, errorFirstCallback);\n</code></pre>\n<p>The JavaScript <code>try…catch</code> mechanism <strong>cannot</strong> be used to intercept errors\ngenerated by asynchronous APIs. A common mistake for beginners is to try to\nuse <code>throw</code> inside an error-first callback:</p>\n<pre><code class=\"lang-js\">// THIS WILL NOT WORK:\nconst fs = require(&#39;fs&#39;);\n\ntry {\n fs.readFile(&#39;/some/file/that/does-not-exist&#39;, (err, data) =&gt; {\n // mistaken assumption: throwing here...\n if (err) {\n throw err;\n }\n });\n} catch (err) {\n // This will not catch the throw!\n console.error(err);\n}\n</code></pre>\n<p>This will not work because the callback function passed to <code>fs.readFile()</code> is\ncalled asynchronously. By the time the callback has been called, the\nsurrounding code (including the <code>try { } catch (err) { }</code> block will have\nalready exited. Throwing an error inside the callback <strong>can crash the Node.js\nprocess</strong> in most cases. If <a href=\"domain.html\">domains</a> are enabled, or a handler has been\nregistered with <code>process.on(&#39;uncaughtException&#39;)</code>, such errors can be\nintercepted.</p>\n"
}
]
},
{
"textRaw": "Exceptions vs. Errors",
"name": "Exceptions vs. Errors",
"type": "misc",
"desc": "<p>A JavaScript exception is a value that is thrown as a result of an invalid\noperation or as the target of a <code>throw</code> statement. While it is not required\nthat these values are instances of <code>Error</code> or classes which inherit from\n<code>Error</code>, all exceptions thrown by Node.js or the JavaScript runtime <em>will</em> be\ninstances of <code>Error</code>.</p>\n<p>Some exceptions are <em>unrecoverable</em> at the JavaScript layer. Such exceptions\nwill <em>always</em> cause the Node.js process to crash. Examples include <code>assert()</code>\nchecks or <code>abort()</code> calls in the C++ layer.</p>\n"
},
{
"textRaw": "System Errors",
"name": "system_errors",
"desc": "<p>System errors are generated when exceptions occur within the Node.js\nruntime environment. Typically, these are operational errors that occur\nwhen an application violates an operating system constraint such as attempting\nto read a file that does not exist or when the user does not have sufficient\npermissions.</p>\n<p>System errors are typically generated at the syscall level: an exhaustive list\nof error codes and their meanings is available by running <code>man 2 intro</code> or\n<code>man 3 errno</code> on most Unices; or <a href=\"http://man7.org/linux/man-pages/man3/errno.3.html\">online</a>.</p>\n<p>In Node.js, system errors are represented as augmented <code>Error</code> objects with\nadded properties.</p>\n",
"classes": [
{
"textRaw": "Class: SystemError",
"type": "class",
"name": "SystemError",
"properties": [
{
"textRaw": "error.info",
"name": "info",
"desc": "<p><code>SystemError</code> instances may have an additional <code>info</code> property whose\nvalue is an object with additional details about the error conditions.</p>\n<p>The following properties are provided:</p>\n<ul>\n<li><code>code</code> {string} The string error code</li>\n<li><code>errno</code> {number} The system-provided error number</li>\n<li><code>message</code> {string} A system-provided human readable description of the error</li>\n<li><code>syscall</code> {string} The name of the system call that triggered the error</li>\n<li><code>path</code> {Buffer} When reporting a file system error, the <code>path</code> will identify\nthe file path.</li>\n<li><code>dest</code> {Buffer} When reporting a file system error, the <code>dest</code> will identify\nthe file path destination (if any).</li>\n</ul>\n"
},
{
"textRaw": "`code` {string} ",
"type": "string",
"name": "code",
"desc": "<p>The <code>error.code</code> property is a string representing the error code, which is\ntypically <code>E</code> followed by a sequence of capital letters.</p>\n"
},
{
"textRaw": "`errno` {string|number} ",
"type": "string|number",
"name": "errno",
"desc": "<p>The <code>error.errno</code> property is a number or a string.\nThe number is a <strong>negative</strong> value which corresponds to the error code defined\nin <a href=\"http://docs.libuv.org/en/v1.x/errors.html\"><code>libuv Error handling</code></a>. See <code>uv-errno.h</code> header file\n(<code>deps/uv/include/uv-errno.h</code> in the Node.js source tree) for details. In case\nof a string, it is the same as <code>error.code</code>.</p>\n"
},
{
"textRaw": "`syscall` {string} ",
"type": "string",
"name": "syscall",
"desc": "<p>The <code>error.syscall</code> property is a string describing the <a href=\"http://man7.org/linux/man-pages/man2/syscalls.2.html\">syscall</a> that failed.</p>\n"
},
{
"textRaw": "`path` {string} ",
"type": "string",
"name": "path",
"desc": "<p>When present (e.g. in <code>fs</code> or <code>child_process</code>), the <code>error.path</code> property is a\nstring containing a relevant invalid pathname.</p>\n"
},
{
"textRaw": "`address` {string} ",
"type": "string",
"name": "address",
"desc": "<p>When present (e.g. in <code>net</code> or <code>dgram</code>), the <code>error.address</code> property is a\nstring describing the address to which the connection failed.</p>\n"
},
{
"textRaw": "`port` {number} ",
"type": "number",
"name": "port",
"desc": "<p>When present (e.g. in <code>net</code> or <code>dgram</code>), the <code>error.port</code> property is a number\nrepresenting the connection&#39;s port that is not available.</p>\n"
}
]
}
],
"modules": [
{
"textRaw": "Common System Errors",
"name": "common_system_errors",
"desc": "<p>This list is <strong>not exhaustive</strong>, but enumerates many of the common system\nerrors encountered when writing a Node.js program. An exhaustive list may be\nfound <a href=\"http://man7.org/linux/man-pages/man3/errno.3.html\">here</a>.</p>\n<ul>\n<li><p><code>EACCES</code> (Permission denied): An attempt was made to access a file in a way\nforbidden by its file access permissions.</p>\n</li>\n<li><p><code>EADDRINUSE</code> (Address already in use): An attempt to bind a server\n(<a href=\"net.html\"><code>net</code></a>, <a href=\"http.html\"><code>http</code></a>, or <a href=\"https.html\"><code>https</code></a>) to a local address failed due to\nanother server on the local system already occupying that address.</p>\n</li>\n<li><p><code>ECONNREFUSED</code> (Connection refused): No connection could be made because the\ntarget machine actively refused it. This usually results from trying to\nconnect to a service that is inactive on the foreign host.</p>\n</li>\n<li><p><code>ECONNRESET</code> (Connection reset by peer): A connection was forcibly closed by\na peer. This normally results from a loss of the connection on the remote\nsocket due to a timeout or reboot. Commonly encountered via the <a href=\"http.html\"><code>http</code></a>\nand <a href=\"net.html\"><code>net</code></a> modules.</p>\n</li>\n<li><p><code>EEXIST</code> (File exists): An existing file was the target of an operation that\nrequired that the target not exist.</p>\n</li>\n<li><p><code>EISDIR</code> (Is a directory): An operation expected a file, but the given\npathname was a directory.</p>\n</li>\n<li><p><code>EMFILE</code> (Too many open files in system): Maximum number of\n<a href=\"https://en.wikipedia.org/wiki/File_descriptor\">file descriptors</a> allowable on the system has been reached, and\nrequests for another descriptor cannot be fulfilled until at least one\nhas been closed. This is encountered when opening many files at once in\nparallel, especially on systems (in particular, macOS) where there is a low\nfile descriptor limit for processes. To remedy a low limit, run\n<code>ulimit -n 2048</code> in the same shell that will run the Node.js process.</p>\n</li>\n<li><p><code>ENOENT</code> (No such file or directory): Commonly raised by <a href=\"fs.html\"><code>fs</code></a> operations\nto indicate that a component of the specified pathname does not exist — no\nentity (file or directory) could be found by the given path.</p>\n</li>\n<li><p><code>ENOTDIR</code> (Not a directory): A component of the given pathname existed, but\nwas not a directory as expected. Commonly raised by <a href=\"fs.html#fs_fs_readdir_path_options_callback\"><code>fs.readdir</code></a>.</p>\n</li>\n<li><p><code>ENOTEMPTY</code> (Directory not empty): A directory with entries was the target\nof an operation that requires an empty directory — usually <a href=\"fs.html#fs_fs_unlink_path_callback\"><code>fs.unlink</code></a>.</p>\n</li>\n<li><p><code>EPERM</code> (Operation not permitted): An attempt was made to perform an\noperation that requires elevated privileges.</p>\n</li>\n<li><p><code>EPIPE</code> (Broken pipe): A write on a pipe, socket, or FIFO for which there is\nno process to read the data. Commonly encountered at the <a href=\"net.html\"><code>net</code></a> and\n<a href=\"http.html\"><code>http</code></a> layers, indicative that the remote side of the stream being\nwritten to has been closed.</p>\n</li>\n<li><p><code>ETIMEDOUT</code> (Operation timed out): A connect or send request failed because\nthe connected party did not properly respond after a period of time. Usually\nencountered by <a href=\"http.html\"><code>http</code></a> or <a href=\"net.html\"><code>net</code></a> — often a sign that a <code>socket.end()</code>\nwas not properly called.</p>\n</li>\n</ul>\n<p><a id=\"nodejs-error-codes\"></a></p>\n",
"type": "module",
"displayName": "Common System Errors"
}
],
"type": "misc",
"displayName": "System Errors"
},
{
"textRaw": "Node.js Error Codes",
"name": "node.js_error_codes",
"desc": "<p><a id=\"ERR_AMBIGUOUS_ARGUMENT\"></a></p>\n",
"modules": [
{
"textRaw": "ERR_AMBIGUOUS_ARGUMENT",
"name": "err_ambiguous_argument",
"desc": "<p>This is triggered by the <code>assert</code> module in case e.g.,\n<code>assert.throws(fn, message)</code> is used in a way that the message is the thrown\nerror message. This is ambiguous because the message is not verifying the error\nmessage and will only be thrown in case no error is thrown.</p>\n<p><a id=\"ERR_ARG_NOT_ITERABLE\"></a></p>\n",
"type": "module",
"displayName": "ERR_AMBIGUOUS_ARGUMENT"
},
{
"textRaw": "ERR_ARG_NOT_ITERABLE",
"name": "err_arg_not_iterable",
"desc": "<p>An iterable argument (i.e. a value that works with <code>for...of</code> loops) was\nrequired, but not provided to a Node.js API.</p>\n<p><a id=\"ERR_ASSERTION\"></a></p>\n",
"type": "module",
"displayName": "ERR_ARG_NOT_ITERABLE"
},
{
"textRaw": "ERR_ASSERTION",
"name": "err_assertion",
"desc": "<p>A special type of error that can be triggered whenever Node.js detects an\nexceptional logic violation that should never occur. These are raised typically\nby the <code>assert</code> module.</p>\n<p><a id=\"ERR_ASYNC_CALLBACK\"></a></p>\n",
"type": "module",
"displayName": "ERR_ASSERTION"
},
{
"textRaw": "ERR_ASYNC_CALLBACK",
"name": "err_async_callback",
"desc": "<p>An attempt was made to register something that is not a function as an\n<code>AsyncHooks</code> callback.</p>\n<p><a id=\"ERR_ASYNC_TYPE\"></a></p>\n",
"type": "module",
"displayName": "ERR_ASYNC_CALLBACK"
},
{
"textRaw": "ERR_ASYNC_TYPE",
"name": "err_async_type",
"desc": "<p>The type of an asynchronous resource was invalid. Note that users are also able\nto define their own types if using the public embedder API.</p>\n<p><a id=\"ERR_BUFFER_OUT_OF_BOUNDS\"></a></p>\n",
"type": "module",
"displayName": "ERR_ASYNC_TYPE"
},
{
"textRaw": "ERR_BUFFER_OUT_OF_BOUNDS",
"name": "err_buffer_out_of_bounds",
"desc": "<p>An operation outside the bounds of a <code>Buffer</code> was attempted.</p>\n<p><a id=\"ERR_BUFFER_TOO_LARGE\"></a></p>\n",
"type": "module",
"displayName": "ERR_BUFFER_OUT_OF_BOUNDS"
},
{
"textRaw": "ERR_BUFFER_TOO_LARGE",
"name": "err_buffer_too_large",
"desc": "<p>An attempt has been made to create a <code>Buffer</code> larger than the maximum allowed\nsize.</p>\n<p><a id=\"ERR_CANNOT_TRANSFER_OBJECT\"></a></p>\n",
"type": "module",
"displayName": "ERR_BUFFER_TOO_LARGE"
},
{
"textRaw": "ERR_CANNOT_TRANSFER_OBJECT",
"name": "err_cannot_transfer_object",
"desc": "<p>The value passed to <code>postMessage()</code> contained an object that is not supported\nfor transferring.</p>\n<p><a id=\"ERR_CANNOT_WATCH_SIGINT\"></a></p>\n",
"type": "module",
"displayName": "ERR_CANNOT_TRANSFER_OBJECT"
},
{
"textRaw": "ERR_CANNOT_WATCH_SIGINT",
"name": "err_cannot_watch_sigint",
"desc": "<p>Node.js was unable to watch for the <code>SIGINT</code> signal.</p>\n<p><a id=\"ERR_CHILD_CLOSED_BEFORE_REPLY\"></a></p>\n",
"type": "module",
"displayName": "ERR_CANNOT_WATCH_SIGINT"
},
{
"textRaw": "ERR_CHILD_CLOSED_BEFORE_REPLY",
"name": "err_child_closed_before_reply",
"desc": "<p>A child process was closed before the parent received a reply.</p>\n<p><a id=\"ERR_CHILD_PROCESS_IPC_REQUIRED\"></a></p>\n",
"type": "module",
"displayName": "ERR_CHILD_CLOSED_BEFORE_REPLY"
},
{
"textRaw": "ERR_CHILD_PROCESS_IPC_REQUIRED",
"name": "err_child_process_ipc_required",
"desc": "<p>Used when a child process is being forked without specifying an IPC channel.</p>\n<p><a id=\"ERR_CHILD_PROCESS_STDIO_MAXBUFFER\"></a></p>\n",
"type": "module",
"displayName": "ERR_CHILD_PROCESS_IPC_REQUIRED"
},
{
"textRaw": "ERR_CHILD_PROCESS_STDIO_MAXBUFFER",
"name": "err_child_process_stdio_maxbuffer",
"desc": "<p>Used when the main process is trying to read data from the child process&#39;s\nSTDERR/STDOUT, and the data&#39;s length is longer than the <code>maxBuffer</code> option.</p>\n<p><a id=\"ERR_CLOSED_MESSAGE_PORT\"></a></p>\n",
"type": "module",
"displayName": "ERR_CHILD_PROCESS_STDIO_MAXBUFFER"
},
{
"textRaw": "ERR_CLOSED_MESSAGE_PORT",
"name": "err_closed_message_port",
"desc": "<p>There was an attempt to use a <code>MessagePort</code> instance in a closed\nstate, usually after <code>.close()</code> has been called.</p>\n<p><a id=\"ERR_CONSOLE_WRITABLE_STREAM\"></a></p>\n",
"type": "module",
"displayName": "ERR_CLOSED_MESSAGE_PORT"
},
{
"textRaw": "ERR_CONSOLE_WRITABLE_STREAM",
"name": "err_console_writable_stream",
"desc": "<p><code>Console</code> was instantiated without <code>stdout</code> stream, or <code>Console</code> has a\nnon-writable <code>stdout</code> or <code>stderr</code> stream.</p>\n<p><a id=\"ERR_CONSTRUCT_CALL_REQUIRED\"></a></p>\n",
"type": "module",
"displayName": "ERR_CONSOLE_WRITABLE_STREAM"
},
{
"textRaw": "ERR_CONSTRUCT_CALL_REQUIRED",
"name": "err_construct_call_required",
"desc": "<p>A constructor for a class was called without <code>new</code>.</p>\n<p><a id=\"ERR_CPU_USAGE\"></a></p>\n",
"type": "module",
"displayName": "ERR_CONSTRUCT_CALL_REQUIRED"
},
{
"textRaw": "ERR_CPU_USAGE",
"name": "err_cpu_usage",
"desc": "<p>The native call from <code>process.cpuUsage</code> could not be processed.</p>\n<p><a id=\"ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED\"></a></p>\n",
"type": "module",
"displayName": "ERR_CPU_USAGE"
},
{
"textRaw": "ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED",
"name": "err_crypto_custom_engine_not_supported",
"desc": "<p>A client certificate engine was requested that is not supported by the version\nof OpenSSL being used.</p>\n<p><a id=\"ERR_CRYPTO_ECDH_INVALID_FORMAT\"></a></p>\n",
"type": "module",
"displayName": "ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED"
},
{
"textRaw": "ERR_CRYPTO_ECDH_INVALID_FORMAT",
"name": "err_crypto_ecdh_invalid_format",
"desc": "<p>An invalid value for the <code>format</code> argument was passed to the <code>crypto.ECDH()</code>\nclass <code>getPublicKey()</code> method.</p>\n<p><a id=\"ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY\"></a></p>\n",
"type": "module",
"displayName": "ERR_CRYPTO_ECDH_INVALID_FORMAT"
},
{
"textRaw": "ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY",
"name": "err_crypto_ecdh_invalid_public_key",
"desc": "<p>An invalid value for the <code>key</code> argument has been passed to the\n<code>crypto.ECDH()</code> class <code>computeSecret()</code> method. It means that the public\nkey lies outside of the elliptic curve.</p>\n<p><a id=\"ERR_CRYPTO_ENGINE_UNKNOWN\"></a></p>\n",
"type": "module",
"displayName": "ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY"
},
{
"textRaw": "ERR_CRYPTO_ENGINE_UNKNOWN",
"name": "err_crypto_engine_unknown",
"desc": "<p>An invalid crypto engine identifier was passed to\n<a href=\"crypto.html#crypto_crypto_setengine_engine_flags\"><code>require(&#39;crypto&#39;).setEngine()</code></a>.</p>\n<p><a id=\"ERR_CRYPTO_FIPS_FORCED\"></a></p>\n",
"type": "module",
"displayName": "ERR_CRYPTO_ENGINE_UNKNOWN"
},
{
"textRaw": "ERR_CRYPTO_FIPS_FORCED",
"name": "err_crypto_fips_forced",
"desc": "<p>The <a href=\"cli.html#cli_force_fips\"><code>--force-fips</code></a> command-line argument was used but there was an attempt\nto enable or disable FIPS mode in the <code>crypto</code> module.</p>\n<p><a id=\"ERR_CRYPTO_FIPS_UNAVAILABLE\"></a></p>\n",
"type": "module",
"displayName": "ERR_CRYPTO_FIPS_FORCED"
},
{
"textRaw": "ERR_CRYPTO_FIPS_UNAVAILABLE",
"name": "err_crypto_fips_unavailable",
"desc": "<p>An attempt was made to enable or disable FIPS mode, but FIPS mode was not\navailable.</p>\n<p><a id=\"ERR_CRYPTO_HASH_DIGEST_NO_UTF16\"></a></p>\n",
"type": "module",
"displayName": "ERR_CRYPTO_FIPS_UNAVAILABLE"
},
{
"textRaw": "ERR_CRYPTO_HASH_DIGEST_NO_UTF16",
"name": "err_crypto_hash_digest_no_utf16",
"desc": "<p>The UTF-16 encoding was used with <a href=\"crypto.html#crypto_hash_digest_encoding\"><code>hash.digest()</code></a>. While the\n<code>hash.digest()</code> method does allow an <code>encoding</code> argument to be passed in,\ncausing the method to return a string rather than a <code>Buffer</code>, the UTF-16\nencoding (e.g. <code>ucs</code> or <code>utf16le</code>) is not supported.</p>\n<p><a id=\"ERR_CRYPTO_HASH_FINALIZED\"></a></p>\n",
"type": "module",
"displayName": "ERR_CRYPTO_HASH_DIGEST_NO_UTF16"
},
{
"textRaw": "ERR_CRYPTO_HASH_FINALIZED",
"name": "err_crypto_hash_finalized",
"desc": "<p><a href=\"crypto.html#crypto_hash_digest_encoding\"><code>hash.digest()</code></a> was called multiple times. The <code>hash.digest()</code> method must\nbe called no more than one time per instance of a <code>Hash</code> object.</p>\n<p><a id=\"ERR_CRYPTO_HASH_UPDATE_FAILED\"></a></p>\n",
"type": "module",
"displayName": "ERR_CRYPTO_HASH_FINALIZED"
},
{
"textRaw": "ERR_CRYPTO_HASH_UPDATE_FAILED",
"name": "err_crypto_hash_update_failed",
"desc": "<p><a href=\"crypto.html#crypto_hash_update_data_inputencoding\"><code>hash.update()</code></a> failed for any reason. This should rarely, if ever, happen.</p>\n<p><a id=\"ERR_CRYPTO_INVALID_DIGEST\"></a></p>\n",
"type": "module",
"displayName": "ERR_CRYPTO_HASH_UPDATE_FAILED"
},
{
"textRaw": "ERR_CRYPTO_INVALID_DIGEST",
"name": "err_crypto_invalid_digest",
"desc": "<p>An invalid <a href=\"crypto.html#crypto_crypto_gethashes\">crypto digest algorithm</a> was specified.</p>\n<p><a id=\"ERR_CRYPTO_INVALID_STATE\"></a></p>\n",
"type": "module",
"displayName": "ERR_CRYPTO_INVALID_DIGEST"
},
{
"textRaw": "ERR_CRYPTO_INVALID_STATE",
"name": "err_crypto_invalid_state",
"desc": "<p>A crypto method was used on an object that was in an invalid state. For\ninstance, calling <a href=\"crypto.html#crypto_cipher_getauthtag\"><code>cipher.getAuthTag()</code></a> before calling <code>cipher.final()</code>.</p>\n<p><a id=\"ERR_CRYPTO_PBKDF2_ERROR\"></a></p>\n",
"type": "module",
"displayName": "ERR_CRYPTO_INVALID_STATE"
},
{
"textRaw": "ERR_CRYPTO_PBKDF2_ERROR",
"name": "err_crypto_pbkdf2_error",
"desc": "<p>The PBKDF2 algorithm failed for unspecified reasons. OpenSSL does not provide\nmore details and therefore neither does Node.js.</p>\n<p><a id=\"ERR_CRYPTO_SCRYPT_INVALID_PARAMETER\"></a></p>\n",
"type": "module",
"displayName": "ERR_CRYPTO_PBKDF2_ERROR"
},
{
"textRaw": "ERR_CRYPTO_SCRYPT_INVALID_PARAMETER",
"name": "err_crypto_scrypt_invalid_parameter",
"desc": "<p>One or more <a href=\"crypto.html#crypto_crypto_scrypt_password_salt_keylen_options_callback\"><code>crypto.scrypt()</code></a> or <a href=\"crypto.html#crypto_crypto_scryptsync_password_salt_keylen_options\"><code>crypto.scryptSync()</code></a> parameters are\noutside their legal range.</p>\n<p><a id=\"ERR_CRYPTO_SCRYPT_NOT_SUPPORTED\"></a></p>\n",
"type": "module",
"displayName": "ERR_CRYPTO_SCRYPT_INVALID_PARAMETER"
},
{
"textRaw": "ERR_CRYPTO_SCRYPT_NOT_SUPPORTED",
"name": "err_crypto_scrypt_not_supported",
"desc": "<p>Node.js was compiled without <code>scrypt</code> support. Not possible with the official\nrelease binaries but can happen with custom builds, including distro builds.</p>\n<p><a id=\"ERR_CRYPTO_SIGN_KEY_REQUIRED\"></a></p>\n",
"type": "module",
"displayName": "ERR_CRYPTO_SCRYPT_NOT_SUPPORTED"
},
{
"textRaw": "ERR_CRYPTO_SIGN_KEY_REQUIRED",
"name": "err_crypto_sign_key_required",
"desc": "<p>A signing <code>key</code> was not provided to the <a href=\"crypto.html#crypto_sign_sign_privatekey_outputformat\"><code>sign.sign()</code></a> method.</p>\n<p><a id=\"ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH\"></a></p>\n",
"type": "module",
"displayName": "ERR_CRYPTO_SIGN_KEY_REQUIRED"
},
{
"textRaw": "ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH",
"name": "err_crypto_timing_safe_equal_length",
"desc": "<p><a href=\"crypto.html#crypto_crypto_timingsafeequal_a_b\"><code>crypto.timingSafeEqual()</code></a> was called with <code>Buffer</code>, <code>TypedArray</code>, or\n<code>DataView</code> arguments of different lengths.</p>\n<p><a id=\"ERR_DNS_SET_SERVERS_FAILED\"></a></p>\n",
"type": "module",
"displayName": "ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH"
},
{
"textRaw": "ERR_DNS_SET_SERVERS_FAILED",
"name": "err_dns_set_servers_failed",
"desc": "<p><code>c-ares</code> failed to set the DNS server.</p>\n<p><a id=\"ERR_DOMAIN_CALLBACK_NOT_AVAILABLE\"></a></p>\n",
"type": "module",
"displayName": "ERR_DNS_SET_SERVERS_FAILED"
},
{
"textRaw": "ERR_DOMAIN_CALLBACK_NOT_AVAILABLE",
"name": "err_domain_callback_not_available",
"desc": "<p>The <code>domain</code> module was not usable since it could not establish the required\nerror handling hooks, because\n<a href=\"process.html#process_process_setuncaughtexceptioncapturecallback_fn\"><code>process.setUncaughtExceptionCaptureCallback()</code></a> had been called at an\nearlier point in time.</p>\n<p><a id=\"ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE\"></a></p>\n",
"type": "module",
"displayName": "ERR_DOMAIN_CALLBACK_NOT_AVAILABLE"
},
{
"textRaw": "ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE",
"name": "err_domain_cannot_set_uncaught_exception_capture",
"desc": "<p><a href=\"process.html#process_process_setuncaughtexceptioncapturecallback_fn\"><code>process.setUncaughtExceptionCaptureCallback()</code></a> could not be called\nbecause the <code>domain</code> module has been loaded at an earlier point in time.</p>\n<p>The stack trace is extended to include the point in time at which the\n<code>domain</code> module had been loaded.</p>\n<p><a id=\"ERR_ENCODING_INVALID_ENCODED_DATA\"></a></p>\n",
"type": "module",
"displayName": "ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE"
},
{
"textRaw": "ERR_ENCODING_INVALID_ENCODED_DATA",
"name": "err_encoding_invalid_encoded_data",
"desc": "<p>Data provided to <code>util.TextDecoder()</code> API was invalid according to the encoding\nprovided.</p>\n<p><a id=\"ERR_ENCODING_NOT_SUPPORTED\"></a></p>\n",
"type": "module",
"displayName": "ERR_ENCODING_INVALID_ENCODED_DATA"
},
{
"textRaw": "ERR_ENCODING_NOT_SUPPORTED",
"name": "err_encoding_not_supported",
"desc": "<p>Encoding provided to <code>util.TextDecoder()</code> API was not one of the\n<a href=\"util.html#util_whatwg_supported_encodings\">WHATWG Supported Encodings</a>.</p>\n<p><a id=\"ERR_FALSY_VALUE_REJECTION\"></a></p>\n",
"type": "module",
"displayName": "ERR_ENCODING_NOT_SUPPORTED"
},
{
"textRaw": "ERR_FALSY_VALUE_REJECTION",
"name": "err_falsy_value_rejection",
"desc": "<p>A <code>Promise</code> that was callbackified via <code>util.callbackify()</code> was rejected with a\nfalsy value.</p>\n<p><a id=\"ERR_FS_FILE_TOO_LARGE\"></a></p>\n",
"type": "module",
"displayName": "ERR_FALSY_VALUE_REJECTION"
},
{
"textRaw": "ERR_FS_FILE_TOO_LARGE",
"name": "err_fs_file_too_large",
"desc": "<p>An attempt has been made to read a file whose size is larger than the maximum\nallowed size for a <code>Buffer</code>.</p>\n<p><a id=\"ERR_FS_INVALID_SYMLINK_TYPE\"></a></p>\n",
"type": "module",
"displayName": "ERR_FS_FILE_TOO_LARGE"
},
{
"textRaw": "ERR_FS_INVALID_SYMLINK_TYPE",
"name": "err_fs_invalid_symlink_type",
"desc": "<p>An invalid symlink type was passed to the <a href=\"fs.html#fs_fs_symlink_target_path_type_callback\"><code>fs.symlink()</code></a> or\n<a href=\"fs.html#fs_fs_symlinksync_target_path_type\"><code>fs.symlinkSync()</code></a> methods.</p>\n<p><a id=\"ERR_HTTP_HEADERS_SENT\"></a></p>\n",
"type": "module",
"displayName": "ERR_FS_INVALID_SYMLINK_TYPE"
},
{
"textRaw": "ERR_HTTP_HEADERS_SENT",
"name": "err_http_headers_sent",
"desc": "<p>An attempt was made to add more headers after the headers had already been sent.</p>\n<p><a id=\"ERR_HTTP_INVALID_HEADER_VALUE\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP_HEADERS_SENT"
},
{
"textRaw": "ERR_HTTP_INVALID_HEADER_VALUE",
"name": "err_http_invalid_header_value",
"desc": "<p>An invalid HTTP header value was specified.</p>\n<p><a id=\"ERR_HTTP_INVALID_STATUS_CODE\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP_INVALID_HEADER_VALUE"
},
{
"textRaw": "ERR_HTTP_INVALID_STATUS_CODE",
"name": "err_http_invalid_status_code",
"desc": "<p>Status code was outside the regular status code range (100-999).</p>\n<p><a id=\"ERR_HTTP_TRAILER_INVALID\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP_INVALID_STATUS_CODE"
},
{
"textRaw": "ERR_HTTP_TRAILER_INVALID",
"name": "err_http_trailer_invalid",
"desc": "<p>The <code>Trailer</code> header was set even though the transfer encoding does not support\nthat.</p>\n<p><a id=\"ERR_HTTP2_ALTSVC_INVALID_ORIGIN\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP_TRAILER_INVALID"
},
{
"textRaw": "ERR_HTTP2_ALTSVC_INVALID_ORIGIN",
"name": "err_http2_altsvc_invalid_origin",
"desc": "<p>HTTP/2 ALTSVC frames require a valid origin.</p>\n<p><a id=\"ERR_HTTP2_ALTSVC_LENGTH\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_ALTSVC_INVALID_ORIGIN"
},
{
"textRaw": "ERR_HTTP2_ALTSVC_LENGTH",
"name": "err_http2_altsvc_length",
"desc": "<p>HTTP/2 ALTSVC frames are limited to a maximum of 16,382 payload bytes.</p>\n<p><a id=\"ERR_HTTP2_CONNECT_AUTHORITY\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_ALTSVC_LENGTH"
},
{
"textRaw": "ERR_HTTP2_CONNECT_AUTHORITY",
"name": "err_http2_connect_authority",
"desc": "<p>For HTTP/2 requests using the <code>CONNECT</code> method, the <code>:authority</code> pseudo-header\nis required.</p>\n<p><a id=\"ERR_HTTP2_CONNECT_PATH\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_CONNECT_AUTHORITY"
},
{
"textRaw": "ERR_HTTP2_CONNECT_PATH",
"name": "err_http2_connect_path",
"desc": "<p>For HTTP/2 requests using the <code>CONNECT</code> method, the <code>:path</code> pseudo-header is\nforbidden.</p>\n<p><a id=\"ERR_HTTP2_CONNECT_SCHEME\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_CONNECT_PATH"
},
{
"textRaw": "ERR_HTTP2_CONNECT_SCHEME",
"name": "err_http2_connect_scheme",
"desc": "<p>For HTTP/2 requests using the <code>CONNECT</code> method, the <code>:scheme</code> pseudo-header is\nforbidden.</p>\n<p><a id=\"ERR_HTTP2_ERROR\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_CONNECT_SCHEME"
},
{
"textRaw": "ERR_HTTP2_ERROR",
"name": "err_http2_error",
"desc": "<p>A non-specific HTTP/2 error has occurred.</p>\n<p><a id=\"ERR_HTTP2_GOAWAY_SESSION\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_ERROR"
},
{
"textRaw": "ERR_HTTP2_GOAWAY_SESSION",
"name": "err_http2_goaway_session",
"desc": "<p>New HTTP/2 Streams may not be opened after the <code>Http2Session</code> has received a\n<code>GOAWAY</code> frame from the connected peer.</p>\n<p><a id=\"ERR_HTTP2_HEADERS_AFTER_RESPOND\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_GOAWAY_SESSION"
},
{
"textRaw": "ERR_HTTP2_HEADERS_AFTER_RESPOND",
"name": "err_http2_headers_after_respond",
"desc": "<p>An additional headers was specified after an HTTP/2 response was initiated.</p>\n<p><a id=\"ERR_HTTP2_HEADERS_SENT\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_HEADERS_AFTER_RESPOND"
},
{
"textRaw": "ERR_HTTP2_HEADERS_SENT",
"name": "err_http2_headers_sent",
"desc": "<p>An attempt was made to send multiple response headers.</p>\n<p><a id=\"ERR_HTTP2_HEADER_SINGLE_VALUE\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_HEADERS_SENT"
},
{
"textRaw": "ERR_HTTP2_HEADER_SINGLE_VALUE",
"name": "err_http2_header_single_value",
"desc": "<p>Multiple values were provided for an HTTP/2 header field that was required to\nhave only a single value.</p>\n<p><a id=\"ERR_HTTP2_INFO_STATUS_NOT_ALLOWED\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_HEADER_SINGLE_VALUE"
},
{
"textRaw": "ERR_HTTP2_INFO_STATUS_NOT_ALLOWED",
"name": "err_http2_info_status_not_allowed",
"desc": "<p>Informational HTTP status codes (<code>1xx</code>) may not be set as the response status\ncode on HTTP/2 responses.</p>\n<p><a id=\"ERR_HTTP2_INVALID_CONNECTION_HEADERS\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_INFO_STATUS_NOT_ALLOWED"
},
{
"textRaw": "ERR_HTTP2_INVALID_CONNECTION_HEADERS",
"name": "err_http2_invalid_connection_headers",
"desc": "<p>HTTP/1 connection specific headers are forbidden to be used in HTTP/2\nrequests and responses.</p>\n<p><a id=\"ERR_HTTP2_INVALID_HEADER_VALUE\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_INVALID_CONNECTION_HEADERS"
},
{
"textRaw": "ERR_HTTP2_INVALID_HEADER_VALUE",
"name": "err_http2_invalid_header_value",
"desc": "<p>An invalid HTTP/2 header value was specified.</p>\n<p><a id=\"ERR_HTTP2_INVALID_INFO_STATUS\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_INVALID_HEADER_VALUE"
},
{
"textRaw": "ERR_HTTP2_INVALID_INFO_STATUS",
"name": "err_http2_invalid_info_status",
"desc": "<p>An invalid HTTP informational status code has been specified. Informational\nstatus codes must be an integer between <code>100</code> and <code>199</code> (inclusive).</p>\n<p><a id=\"ERR_HTTP2_INVALID_PACKED_SETTINGS_LENGTH\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_INVALID_INFO_STATUS"
},
{
"textRaw": "ERR_HTTP2_INVALID_PACKED_SETTINGS_LENGTH",
"name": "err_http2_invalid_packed_settings_length",
"desc": "<p>Input <code>Buffer</code> and <code>Uint8Array</code> instances passed to the\n<code>http2.getUnpackedSettings()</code> API must have a length that is a multiple of\nsix.</p>\n<p><a id=\"ERR_HTTP2_INVALID_PSEUDOHEADER\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_INVALID_PACKED_SETTINGS_LENGTH"
},
{
"textRaw": "ERR_HTTP2_INVALID_PSEUDOHEADER",
"name": "err_http2_invalid_pseudoheader",
"desc": "<p>Only valid HTTP/2 pseudoheaders (<code>:status</code>, <code>:path</code>, <code>:authority</code>, <code>:scheme</code>,\nand <code>:method</code>) may be used.</p>\n<p><a id=\"ERR_HTTP2_INVALID_SESSION\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_INVALID_PSEUDOHEADER"
},
{
"textRaw": "ERR_HTTP2_INVALID_SESSION",
"name": "err_http2_invalid_session",
"desc": "<p>An action was performed on an <code>Http2Session</code> object that had already been\ndestroyed.</p>\n<p><a id=\"ERR_HTTP2_INVALID_SETTING_VALUE\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_INVALID_SESSION"
},
{
"textRaw": "ERR_HTTP2_INVALID_SETTING_VALUE",
"name": "err_http2_invalid_setting_value",
"desc": "<p>An invalid value has been specified for an HTTP/2 setting.</p>\n<p><a id=\"ERR_HTTP2_INVALID_STREAM\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_INVALID_SETTING_VALUE"
},
{
"textRaw": "ERR_HTTP2_INVALID_STREAM",
"name": "err_http2_invalid_stream",
"desc": "<p>An operation was performed on a stream that had already been destroyed.</p>\n<p><a id=\"ERR_HTTP2_MAX_PENDING_SETTINGS_ACK\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_INVALID_STREAM"
},
{
"textRaw": "ERR_HTTP2_MAX_PENDING_SETTINGS_ACK",
"name": "err_http2_max_pending_settings_ack",
"desc": "<p>Whenever an HTTP/2 <code>SETTINGS</code> frame is sent to a connected peer, the peer is\nrequired to send an acknowledgment that it has received and applied the new\n<code>SETTINGS</code>. By default, a maximum number of unacknowledged <code>SETTINGS</code> frames may\nbe sent at any given time. This error code is used when that limit has been\nreached.</p>\n<p><a id=\"ERR_HTTP2_NO_SOCKET_MANIPULATION\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_MAX_PENDING_SETTINGS_ACK"
},
{
"textRaw": "ERR_HTTP2_NO_SOCKET_MANIPULATION",
"name": "err_http2_no_socket_manipulation",
"desc": "<p>An attempt was made to directly manipulate (read, write, pause, resume, etc.) a\nsocket attached to an <code>Http2Session</code>.</p>\n<p><a id=\"ERR_HTTP2_OUT_OF_STREAMS\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_NO_SOCKET_MANIPULATION"
},
{
"textRaw": "ERR_HTTP2_OUT_OF_STREAMS",
"name": "err_http2_out_of_streams",
"desc": "<p>The number of streams created on a single HTTP/2 session reached the maximum\nlimit.</p>\n<p><a id=\"ERR_HTTP2_PAYLOAD_FORBIDDEN\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_OUT_OF_STREAMS"
},
{
"textRaw": "ERR_HTTP2_PAYLOAD_FORBIDDEN",
"name": "err_http2_payload_forbidden",
"desc": "<p>A message payload was specified for an HTTP response code for which a payload is\nforbidden.</p>\n<p><a id=\"ERR_HTTP2_PING_CANCEL\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_PAYLOAD_FORBIDDEN"
},
{
"textRaw": "ERR_HTTP2_PING_CANCEL",
"name": "err_http2_ping_cancel",
"desc": "<p>An HTTP/2 ping was canceled.</p>\n<p><a id=\"ERR_HTTP2_PING_LENGTH\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_PING_CANCEL"
},
{
"textRaw": "ERR_HTTP2_PING_LENGTH",
"name": "err_http2_ping_length",
"desc": "<p>HTTP/2 ping payloads must be exactly 8 bytes in length.</p>\n<p><a id=\"ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_PING_LENGTH"
},
{
"textRaw": "ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED",
"name": "err_http2_pseudoheader_not_allowed",
"desc": "<p>An HTTP/2 pseudo-header has been used inappropriately. Pseudo-headers are header\nkey names that begin with the <code>:</code> prefix.</p>\n<p><a id=\"ERR_HTTP2_PUSH_DISABLED\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED"
},
{
"textRaw": "ERR_HTTP2_PUSH_DISABLED",
"name": "err_http2_push_disabled",
"desc": "<p>An attempt was made to create a push stream, which had been disabled by the\nclient.</p>\n<p><a id=\"ERR_HTTP2_SEND_FILE\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_PUSH_DISABLED"
},
{
"textRaw": "ERR_HTTP2_SEND_FILE",
"name": "err_http2_send_file",
"desc": "<p>An attempt was made to use the <code>Http2Stream.prototype.responseWithFile()</code> API to\nsend a directory.</p>\n<p><a id=\"ERR_HTTP2_SEND_FILE_NOSEEK\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_SEND_FILE"
},
{
"textRaw": "ERR_HTTP2_SEND_FILE_NOSEEK",
"name": "err_http2_send_file_noseek",
"desc": "<p>An attempt was made to use the <code>Http2Stream.prototype.responseWithFile()</code> API to\nsend something other than a regular file, but <code>offset</code> or <code>length</code> options were\nprovided.</p>\n<p><a id=\"ERR_HTTP2_SESSION_ERROR\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_SEND_FILE_NOSEEK"
},
{
"textRaw": "ERR_HTTP2_SESSION_ERROR",
"name": "err_http2_session_error",
"desc": "<p>The <code>Http2Session</code> closed with a non-zero error code.</p>\n<p><a id=\"ERR_HTTP2_SOCKET_BOUND\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_SESSION_ERROR"
},
{
"textRaw": "ERR_HTTP2_SOCKET_BOUND",
"name": "err_http2_socket_bound",
"desc": "<p>An attempt was made to connect a <code>Http2Session</code> object to a <code>net.Socket</code> or\n<code>tls.TLSSocket</code> that had already been bound to another <code>Http2Session</code> object.</p>\n<p><a id=\"ERR_HTTP2_STATUS_101\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_SOCKET_BOUND"
},
{
"textRaw": "ERR_HTTP2_STATUS_101",
"name": "err_http2_status_101",
"desc": "<p>Use of the <code>101</code> Informational status code is forbidden in HTTP/2.</p>\n<p><a id=\"ERR_HTTP2_STATUS_INVALID\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_STATUS_101"
},
{
"textRaw": "ERR_HTTP2_STATUS_INVALID",
"name": "err_http2_status_invalid",
"desc": "<p>An invalid HTTP status code has been specified. Status codes must be an integer\nbetween <code>100</code> and <code>599</code> (inclusive).</p>\n<p><a id=\"ERR_HTTP2_STREAM_CANCEL\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_STATUS_INVALID"
},
{
"textRaw": "ERR_HTTP2_STREAM_CANCEL",
"name": "err_http2_stream_cancel",
"desc": "<p>An <code>Http2Stream</code> was destroyed before any data was transmitted to the connected\npeer.</p>\n<p><a id=\"ERR_HTTP2_STREAM_ERROR\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_STREAM_CANCEL"
},
{
"textRaw": "ERR_HTTP2_STREAM_ERROR",
"name": "err_http2_stream_error",
"desc": "<p>A non-zero error code was been specified in an <code>RST_STREAM</code> frame.</p>\n<p><a id=\"ERR_HTTP2_STREAM_SELF_DEPENDENCY\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_STREAM_ERROR"
},
{
"textRaw": "ERR_HTTP2_STREAM_SELF_DEPENDENCY",
"name": "err_http2_stream_self_dependency",
"desc": "<p>When setting the priority for an HTTP/2 stream, the stream may be marked as\na dependency for a parent stream. This error code is used when an attempt is\nmade to mark a stream and dependent of itself.</p>\n<p><a id=\"ERR_HTTP2_TRAILERS_ALREADY_SENT\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_STREAM_SELF_DEPENDENCY"
},
{
"textRaw": "ERR_HTTP2_TRAILERS_ALREADY_SENT",
"name": "err_http2_trailers_already_sent",
"desc": "<p>Trailing headers have already been sent on the <code>Http2Stream</code>.</p>\n<p><a id=\"ERR_HTTP2_TRAILERS_NOT_READY\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_TRAILERS_ALREADY_SENT"
},
{
"textRaw": "ERR_HTTP2_TRAILERS_NOT_READY",
"name": "err_http2_trailers_not_ready",
"desc": "<p>The <code>http2stream.sendTrailers()</code> method cannot be called until after the\n<code>&#39;wantTrailers&#39;</code> event is emitted on an <code>Http2Stream</code> object. The\n<code>&#39;wantTrailers&#39;</code> event will only be emitted if the <code>waitForTrailers</code> option\nis set for the <code>Http2Stream</code>.</p>\n<p><a id=\"ERR_HTTP2_UNSUPPORTED_PROTOCOL\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_TRAILERS_NOT_READY"
},
{
"textRaw": "ERR_HTTP2_UNSUPPORTED_PROTOCOL",
"name": "err_http2_unsupported_protocol",
"desc": "<p><code>http2.connect()</code> was passed a URL that uses any protocol other than <code>http:</code> or\n<code>https:</code>.</p>\n<p><a id=\"ERR_INDEX_OUT_OF_RANGE\"></a></p>\n",
"type": "module",
"displayName": "ERR_HTTP2_UNSUPPORTED_PROTOCOL"
},
{
"textRaw": "ERR_INDEX_OUT_OF_RANGE",
"name": "err_index_out_of_range",
"desc": "<p>A given index was out of the accepted range (e.g. negative offsets).</p>\n<p><a id=\"ERR_INSPECTOR_ALREADY_CONNECTED\"></a></p>\n",
"type": "module",
"displayName": "ERR_INDEX_OUT_OF_RANGE"
},
{
"textRaw": "ERR_INSPECTOR_ALREADY_CONNECTED",
"name": "err_inspector_already_connected",
"desc": "<p>While using the <code>inspector</code> module, an attempt was made to connect when the\ninspector was already connected.</p>\n<p><a id=\"ERR_INSPECTOR_CLOSED\"></a></p>\n",
"type": "module",
"displayName": "ERR_INSPECTOR_ALREADY_CONNECTED"
},
{
"textRaw": "ERR_INSPECTOR_CLOSED",
"name": "err_inspector_closed",
"desc": "<p>While using the <code>inspector</code> module, an attempt was made to use the inspector\nafter the session had already closed.</p>\n<p><a id=\"ERR_INSPECTOR_NOT_AVAILABLE\"></a></p>\n",
"type": "module",
"displayName": "ERR_INSPECTOR_CLOSED"
},
{
"textRaw": "ERR_INSPECTOR_NOT_AVAILABLE",
"name": "err_inspector_not_available",
"desc": "<p>The <code>inspector</code> module is not available for use.</p>\n<p><a id=\"ERR_INSPECTOR_NOT_CONNECTED\"></a></p>\n",
"type": "module",
"displayName": "ERR_INSPECTOR_NOT_AVAILABLE"
},
{
"textRaw": "ERR_INSPECTOR_NOT_CONNECTED",
"name": "err_inspector_not_connected",
"desc": "<p>While using the <code>inspector</code> module, an attempt was made to use the inspector\nbefore it was connected.</p>\n<p><a id=\"ERR_INVALID_ADDRESS_FAMILY\"></a></p>\n",
"type": "module",
"displayName": "ERR_INSPECTOR_NOT_CONNECTED"
},
{
"textRaw": "ERR_INVALID_ADDRESS_FAMILY",
"name": "err_invalid_address_family",
"desc": "<p>The provided address family is not understood by the Node.js API.</p>\n<p><a id=\"ERR_INVALID_ARG_TYPE\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_ADDRESS_FAMILY"
},
{
"textRaw": "ERR_INVALID_ARG_TYPE",
"name": "err_invalid_arg_type",
"desc": "<p>An argument of the wrong type was passed to a Node.js API.</p>\n<p><a id=\"ERR_INVALID_ARG_VALUE\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_ARG_TYPE"
},
{
"textRaw": "ERR_INVALID_ARG_VALUE",
"name": "err_invalid_arg_value",
"desc": "<p>An invalid or unsupported value was passed for a given argument.</p>\n<p><a id=\"ERR_INVALID_ASYNC_ID\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_ARG_VALUE"
},
{
"textRaw": "ERR_INVALID_ASYNC_ID",
"name": "err_invalid_async_id",
"desc": "<p>An invalid <code>asyncId</code> or <code>triggerAsyncId</code> was passed using <code>AsyncHooks</code>. An id\nless than -1 should never happen.</p>\n<p><a id=\"ERR_INVALID_BUFFER_SIZE\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_ASYNC_ID"
},
{
"textRaw": "ERR_INVALID_BUFFER_SIZE",
"name": "err_invalid_buffer_size",
"desc": "<p>A swap was performed on a <code>Buffer</code> but its size was not compatible with the\noperation.</p>\n<p><a id=\"ERR_INVALID_CALLBACK\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_BUFFER_SIZE"
},
{
"textRaw": "ERR_INVALID_CALLBACK",
"name": "err_invalid_callback",
"desc": "<p>A callback function was required but was not been provided to a Node.js API.</p>\n<p><a id=\"ERR_INVALID_CHAR\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_CALLBACK"
},
{
"textRaw": "ERR_INVALID_CHAR",
"name": "err_invalid_char",
"desc": "<p>Invalid characters were detected in headers.</p>\n<p><a id=\"ERR_INVALID_CURSOR_POS\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_CHAR"
},
{
"textRaw": "ERR_INVALID_CURSOR_POS",
"name": "err_invalid_cursor_pos",
"desc": "<p>A cursor on a given stream cannot be moved to a specified row without a\nspecified column.</p>\n<p><a id=\"ERR_INVALID_FD\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_CURSOR_POS"
},
{
"textRaw": "ERR_INVALID_FD",
"name": "err_invalid_fd",
"desc": "<p>A file descriptor (&#39;fd&#39;) was not valid (e.g. it was a negative value).</p>\n<p><a id=\"ERR_INVALID_FD_TYPE\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_FD"
},
{
"textRaw": "ERR_INVALID_FD_TYPE",
"name": "err_invalid_fd_type",
"desc": "<p>A file descriptor (&#39;fd&#39;) type was not valid.</p>\n<p><a id=\"ERR_INVALID_FILE_URL_HOST\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_FD_TYPE"
},
{
"textRaw": "ERR_INVALID_FILE_URL_HOST",
"name": "err_invalid_file_url_host",
"desc": "<p>A Node.js API that consumes <code>file:</code> URLs (such as certain functions in the\n<a href=\"fs.html\"><code>fs</code></a> module) encountered a file URL with an incompatible host. This\nsituation can only occur on Unix-like systems where only <code>localhost</code> or an empty\nhost is supported.</p>\n<p><a id=\"ERR_INVALID_FILE_URL_PATH\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_FILE_URL_HOST"
},
{
"textRaw": "ERR_INVALID_FILE_URL_PATH",
"name": "err_invalid_file_url_path",
"desc": "<p>A Node.js API that consumes <code>file:</code> URLs (such as certain functions in the\n<a href=\"fs.html\"><code>fs</code></a> module) encountered a file URL with an incompatible path. The exact\nsemantics for determining whether a path can be used is platform-dependent.</p>\n<p><a id=\"ERR_INVALID_HANDLE_TYPE\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_FILE_URL_PATH"
},
{
"textRaw": "ERR_INVALID_HANDLE_TYPE",
"name": "err_invalid_handle_type",
"desc": "<p>An attempt was made to send an unsupported &quot;handle&quot; over an IPC communication\nchannel to a child process. See <a href=\"child_process.html#child_process_subprocess_send_message_sendhandle_options_callback\"><code>subprocess.send()</code></a> and <a href=\"process.html#process_process_send_message_sendhandle_options_callback\"><code>process.send()</code></a> for\nmore information.</p>\n<p><a id=\"ERR_INVALID_HTTP_TOKEN\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_HANDLE_TYPE"
},
{
"textRaw": "ERR_INVALID_HTTP_TOKEN",
"name": "err_invalid_http_token",
"desc": "<p>An invalid HTTP token was supplied.</p>\n<p><a id=\"ERR_INVALID_IP_ADDRESS\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_HTTP_TOKEN"
},
{
"textRaw": "ERR_INVALID_IP_ADDRESS",
"name": "err_invalid_ip_address",
"desc": "<p>An IP address is not valid.</p>\n<p><a id=\"ERR_INVALID_OPT_VALUE\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_IP_ADDRESS"
},
{
"textRaw": "ERR_INVALID_OPT_VALUE",
"name": "err_invalid_opt_value",
"desc": "<p>An invalid or unexpected value was passed in an options object.</p>\n<p><a id=\"ERR_INVALID_OPT_VALUE_ENCODING\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_OPT_VALUE"
},
{
"textRaw": "ERR_INVALID_OPT_VALUE_ENCODING",
"name": "err_invalid_opt_value_encoding",
"desc": "<p>An invalid or unknown file encoding was passed.</p>\n<p><a id=\"ERR_INVALID_PERFORMANCE_MARK\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_OPT_VALUE_ENCODING"
},
{
"textRaw": "ERR_INVALID_PERFORMANCE_MARK",
"name": "err_invalid_performance_mark",
"desc": "<p>While using the Performance Timing API (<code>perf_hooks</code>), a performance mark is\ninvalid.</p>\n<p><a id=\"ERR_INVALID_PROTOCOL\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_PERFORMANCE_MARK"
},
{
"textRaw": "ERR_INVALID_PROTOCOL",
"name": "err_invalid_protocol",
"desc": "<p>An invalid <code>options.protocol</code> was passed.</p>\n<p><a id=\"ERR_INVALID_REPL_EVAL_CONFIG\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_PROTOCOL"
},
{
"textRaw": "ERR_INVALID_REPL_EVAL_CONFIG",
"name": "err_invalid_repl_eval_config",
"desc": "<p>Both <code>breakEvalOnSigint</code> and <code>eval</code> options were set in the REPL config, which\nis not supported.</p>\n<p><a id=\"ERR_INVALID_RETURN_PROPERTY\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_REPL_EVAL_CONFIG"
},
{
"textRaw": "ERR_INVALID_RETURN_PROPERTY",
"name": "err_invalid_return_property",
"desc": "<p>Thrown in case a function option does not provide a valid value for one of its\nreturned object properties on execution.</p>\n<p><a id=\"ERR_INVALID_RETURN_PROPERTY_VALUE\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_RETURN_PROPERTY"
},
{
"textRaw": "ERR_INVALID_RETURN_PROPERTY_VALUE",
"name": "err_invalid_return_property_value",
"desc": "<p>Thrown in case a function option does not provide an expected value\ntype for one of its returned object properties on execution.</p>\n<p><a id=\"ERR_INVALID_RETURN_VALUE\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_RETURN_PROPERTY_VALUE"
},
{
"textRaw": "ERR_INVALID_RETURN_VALUE",
"name": "err_invalid_return_value",
"desc": "<p>Thrown in case a function option does not return an expected value\ntype on execution.\nFor example when a function is expected to return a promise.</p>\n<p><a id=\"ERR_INVALID_SYNC_FORK_INPUT\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_RETURN_VALUE"
},
{
"textRaw": "ERR_INVALID_SYNC_FORK_INPUT",
"name": "err_invalid_sync_fork_input",
"desc": "<p>A <code>Buffer</code>, <code>Uint8Array</code> or <code>string</code> was provided as stdio input to a\nsynchronous fork. See the documentation for the <a href=\"child_process.html\"><code>child_process</code></a> module\nfor more information.</p>\n<p><a id=\"ERR_INVALID_THIS\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_SYNC_FORK_INPUT"
},
{
"textRaw": "ERR_INVALID_THIS",
"name": "err_invalid_this",
"desc": "<p>A Node.js API function was called with an incompatible <code>this</code> value.</p>\n<p>Example:</p>\n<pre><code class=\"lang-js\">const urlSearchParams = new URLSearchParams(&#39;foo=bar&amp;baz=new&#39;);\n\nconst buf = Buffer.alloc(1);\nurlSearchParams.has.call(buf, &#39;foo&#39;);\n// Throws a TypeError with code &#39;ERR_INVALID_THIS&#39;\n</code></pre>\n<p><a id=\"ERR_INVALID_TRANSFER_OBJECT\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_THIS"
},
{
"textRaw": "ERR_INVALID_TRANSFER_OBJECT",
"name": "err_invalid_transfer_object",
"desc": "<p>An invalid transfer object was passed to <code>postMessage()</code>.</p>\n<p><a id=\"ERR_INVALID_TUPLE\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_TRANSFER_OBJECT"
},
{
"textRaw": "ERR_INVALID_TUPLE",
"name": "err_invalid_tuple",
"desc": "<p>An element in the <code>iterable</code> provided to the <a href=\"url.html#url_the_whatwg_url_api\">WHATWG</a>\n<a href=\"url.html#url_constructor_new_urlsearchparams_iterable\"><code>URLSearchParams</code> constructor</a> did not\nrepresent a <code>[name, value]</code> tuple – that is, if an element is not iterable, or\ndoes not consist of exactly two elements.</p>\n<p><a id=\"ERR_INVALID_URI\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_TUPLE"
},
{
"textRaw": "ERR_INVALID_URI",
"name": "err_invalid_uri",
"desc": "<p>An invalid URI was passed.</p>\n<p><a id=\"ERR_INVALID_URL\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_URI"
},
{
"textRaw": "ERR_INVALID_URL",
"name": "err_invalid_url",
"desc": "<p>An invalid URL was passed to the <a href=\"url.html#url_the_whatwg_url_api\">WHATWG</a>\n<a href=\"url.html#url_constructor_new_url_input_base\"><code>URL</code> constructor</a> to be parsed. The thrown error object\ntypically has an additional property <code>&#39;input&#39;</code> that contains the URL that failed\nto parse.</p>\n<p><a id=\"ERR_INVALID_URL_SCHEME\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_URL"
},
{
"textRaw": "ERR_INVALID_URL_SCHEME",
"name": "err_invalid_url_scheme",
"desc": "<p>An attempt was made to use a URL of an incompatible scheme (protocol) for a\nspecific purpose. It is only used in the <a href=\"url.html#url_the_whatwg_url_api\">WHATWG URL API</a> support in the\n<a href=\"fs.html\"><code>fs</code></a> module (which only accepts URLs with <code>&#39;file&#39;</code> scheme), but may be used\nin other Node.js APIs as well in the future.</p>\n<p><a id=\"ERR_IPC_CHANNEL_CLOSED\"></a></p>\n",
"type": "module",
"displayName": "ERR_INVALID_URL_SCHEME"
},
{
"textRaw": "ERR_IPC_CHANNEL_CLOSED",
"name": "err_ipc_channel_closed",
"desc": "<p>An attempt was made to use an IPC communication channel that was already closed.</p>\n<p><a id=\"ERR_IPC_DISCONNECTED\"></a></p>\n",
"type": "module",
"displayName": "ERR_IPC_CHANNEL_CLOSED"
},
{
"textRaw": "ERR_IPC_DISCONNECTED",
"name": "err_ipc_disconnected",
"desc": "<p>An attempt was made to disconnect an IPC communication channel that was already\ndisconnected. See the documentation for the <a href=\"child_process.html\"><code>child_process</code></a> module\nfor more information.</p>\n<p><a id=\"ERR_IPC_ONE_PIPE\"></a></p>\n",
"type": "module",
"displayName": "ERR_IPC_DISCONNECTED"
},
{
"textRaw": "ERR_IPC_ONE_PIPE",
"name": "err_ipc_one_pipe",
"desc": "<p>An attempt was made to create a child Node.js process using more than one IPC\ncommunication channel. See the documentation for the <a href=\"child_process.html\"><code>child_process</code></a> module\nfor more information.</p>\n<p><a id=\"ERR_IPC_SYNC_FORK\"></a></p>\n",
"type": "module",
"displayName": "ERR_IPC_ONE_PIPE"
},
{
"textRaw": "ERR_IPC_SYNC_FORK",
"name": "err_ipc_sync_fork",
"desc": "<p>An attempt was made to open an IPC communication channel with a synchronously\nforked Node.js process. See the documentation for the <a href=\"child_process.html\"><code>child_process</code></a> module\nfor more information.</p>\n<p><a id=\"ERR_MEMORY_ALLOCATION_FAILED\"></a></p>\n",
"type": "module",
"displayName": "ERR_IPC_SYNC_FORK"
},
{
"textRaw": "ERR_MEMORY_ALLOCATION_FAILED",
"name": "err_memory_allocation_failed",
"desc": "<p>An attempt was made to allocate memory (usually in the C++ layer) but it\nfailed.</p>\n<p><a id=\"ERR_METHOD_NOT_IMPLEMENTED\"></a></p>\n",
"type": "module",
"displayName": "ERR_MEMORY_ALLOCATION_FAILED"
},
{
"textRaw": "ERR_METHOD_NOT_IMPLEMENTED",
"name": "err_method_not_implemented",
"desc": "<p>A method is required but not implemented.</p>\n<p><a id=\"ERR_MISSING_ARGS\"></a></p>\n",
"type": "module",
"displayName": "ERR_METHOD_NOT_IMPLEMENTED"
},
{
"textRaw": "ERR_MISSING_ARGS",
"name": "err_missing_args",
"desc": "<p>A required argument of a Node.js API was not passed. This is only used for\nstrict compliance with the API specification (which in some cases may accept\n<code>func(undefined)</code> but not <code>func()</code>). In most native Node.js APIs,\n<code>func(undefined)</code> and <code>func()</code> are treated identically, and the\n<a href=\"#ERR_INVALID_ARG_TYPE\"><code>ERR_INVALID_ARG_TYPE</code></a> error code may be used instead.</p>\n<p><a id=\"ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK\"></a></p>\n",
"type": "module",
"displayName": "ERR_MISSING_ARGS"
},
{
"textRaw": "ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK",
"name": "err_missing_dynamic_instantiate_hook",
"stability": 1,
"stabilityText": "Experimental",
"desc": "<p>An <a href=\"esm.html\">ES6 module</a> loader hook specified <code>format: &#39;dynamic&#39;</code> but did not provide\na <code>dynamicInstantiate</code> hook.</p>\n<p><a id=\"ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST\"></a></p>\n",
"type": "module",
"displayName": "ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK"
},
{
"textRaw": "ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST",
"name": "err_missing_message_port_in_transfer_list",
"desc": "<p>A <code>MessagePort</code> was found in the object passed to a <code>postMessage()</code> call,\nbut not provided in the <code>transferList</code> for that call.</p>\n<p><a id=\"ERR_MISSING_MODULE\"></a></p>\n",
"type": "module",
"displayName": "ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST"
},
{
"textRaw": "ERR_MISSING_MODULE",
"name": "err_missing_module",
"stability": 1,
"stabilityText": "Experimental",
"desc": "<p>An <a href=\"esm.html\">ES6 module</a> could not be resolved.</p>\n<p><a id=\"ERR_MISSING_PLATFORM_FOR_WORKER\"></a></p>\n",
"type": "module",
"displayName": "ERR_MISSING_MODULE"
},
{
"textRaw": "ERR_MISSING_PLATFORM_FOR_WORKER",
"name": "err_missing_platform_for_worker",
"desc": "<p>The V8 platform used by this instance of Node.js does not support creating\nWorkers. This is caused by lack of embedder support for Workers. In particular,\nthis error will not occur with standard builds of Node.js.</p>\n<p><a id=\"ERR_MODULE_RESOLUTION_LEGACY\"></a></p>\n",
"type": "module",
"displayName": "ERR_MISSING_PLATFORM_FOR_WORKER"
},
{
"textRaw": "ERR_MODULE_RESOLUTION_LEGACY",
"name": "err_module_resolution_legacy",
"stability": 1,
"stabilityText": "Experimental",
"desc": "<p>A failure occurred resolving imports in an <a href=\"esm.html\">ES6 module</a>.</p>\n<p><a id=\"ERR_MULTIPLE_CALLBACK\"></a></p>\n",
"type": "module",
"displayName": "ERR_MODULE_RESOLUTION_LEGACY"
},
{
"textRaw": "ERR_MULTIPLE_CALLBACK",
"name": "err_multiple_callback",
"desc": "<p>A callback was called more than once.</p>\n<p>A callback is almost always meant to only be called once as the query\ncan either be fulfilled or rejected but not both at the same time. The latter\nwould be possible by calling a callback more than once.</p>\n<p><a id=\"ERR_NAPI_CONS_FUNCTION\"></a></p>\n",
"type": "module",
"displayName": "ERR_MULTIPLE_CALLBACK"
},
{
"textRaw": "ERR_NAPI_CONS_FUNCTION",
"name": "err_napi_cons_function",
"desc": "<p>While using <code>N-API</code>, a constructor passed was not a function.</p>\n<p><a id=\"ERR_NAPI_INVALID_DATAVIEW_ARGS\"></a></p>\n",
"type": "module",
"displayName": "ERR_NAPI_CONS_FUNCTION"
},
{
"textRaw": "ERR_NAPI_INVALID_DATAVIEW_ARGS",
"name": "err_napi_invalid_dataview_args",
"desc": "<p>While calling <code>napi_create_dataview()</code>, a given <code>offset</code> was outside the bounds\nof the dataview or <code>offset + length</code> was larger than a length of given <code>buffer</code>.</p>\n<p><a id=\"ERR_NAPI_INVALID_TYPEDARRAY_ALIGNMENT\"></a></p>\n",
"type": "module",
"displayName": "ERR_NAPI_INVALID_DATAVIEW_ARGS"
},
{
"textRaw": "ERR_NAPI_INVALID_TYPEDARRAY_ALIGNMENT",
"name": "err_napi_invalid_typedarray_alignment",
"desc": "<p>While calling <code>napi_create_typedarray()</code>, the provided <code>offset</code> was not a\nmultiple of the element size.</p>\n<p><a id=\"ERR_NAPI_INVALID_TYPEDARRAY_LENGTH\"></a></p>\n",
"type": "module",
"displayName": "ERR_NAPI_INVALID_TYPEDARRAY_ALIGNMENT"
},
{
"textRaw": "ERR_NAPI_INVALID_TYPEDARRAY_LENGTH",
"name": "err_napi_invalid_typedarray_length",
"desc": "<p>While calling <code>napi_create_typedarray()</code>, <code>(length * size_of_element) +\nbyte_offset</code> was larger than the length of given <code>buffer</code>.</p>\n<p><a id=\"ERR_NAPI_TSFN_CALL_JS\"></a></p>\n",
"type": "module",
"displayName": "ERR_NAPI_INVALID_TYPEDARRAY_LENGTH"
},
{
"textRaw": "ERR_NAPI_TSFN_CALL_JS",
"name": "err_napi_tsfn_call_js",
"desc": "<p>An error occurred while invoking the JavaScript portion of the thread-safe\nfunction.</p>\n<p><a id=\"ERR_NAPI_TSFN_GET_UNDEFINED\"></a></p>\n",
"type": "module",
"displayName": "ERR_NAPI_TSFN_CALL_JS"
},
{
"textRaw": "ERR_NAPI_TSFN_GET_UNDEFINED",
"name": "err_napi_tsfn_get_undefined",
"desc": "<p>An error occurred while attempting to retrieve the JavaScript <code>undefined</code>\nvalue.</p>\n<p><a id=\"ERR_NAPI_TSFN_START_IDLE_LOOP\"></a></p>\n",
"type": "module",
"displayName": "ERR_NAPI_TSFN_GET_UNDEFINED"
},
{
"textRaw": "ERR_NAPI_TSFN_START_IDLE_LOOP",
"name": "err_napi_tsfn_start_idle_loop",
"desc": "<p>On the main thread, values are removed from the queue associated with the\nthread-safe function in an idle loop. This error indicates that an error\nhas occurred when attempting to start the loop.</p>\n<p><a id=\"ERR_NAPI_TSFN_STOP_IDLE_LOOP\"></a></p>\n",
"type": "module",
"displayName": "ERR_NAPI_TSFN_START_IDLE_LOOP"
},
{
"textRaw": "ERR_NAPI_TSFN_STOP_IDLE_LOOP",
"name": "err_napi_tsfn_stop_idle_loop",
"desc": "<p>Once no more items are left in the queue, the idle loop must be suspended. This\nerror indicates that the idle loop has failed to stop.</p>\n<p><a id=\"ERR_NO_CRYPTO\"></a></p>\n",
"type": "module",
"displayName": "ERR_NAPI_TSFN_STOP_IDLE_LOOP"
},
{
"textRaw": "ERR_NO_CRYPTO",
"name": "err_no_crypto",
"desc": "<p>An attempt was made to use crypto features while Node.js was not compiled with\nOpenSSL crypto support.</p>\n<p><a id=\"ERR_NO_ICU\"></a></p>\n",
"type": "module",
"displayName": "ERR_NO_CRYPTO"
},
{
"textRaw": "ERR_NO_ICU",
"name": "err_no_icu",
"desc": "<p>An attempt was made to use features that require <a href=\"intl.html#intl_internationalization_support\">ICU</a>, but Node.js was not\ncompiled with ICU support.</p>\n<p><a id=\"ERR_NO_LONGER_SUPPORTED\"></a></p>\n",
"type": "module",
"displayName": "ERR_NO_ICU"
},
{
"textRaw": "ERR_NO_LONGER_SUPPORTED",
"name": "err_no_longer_supported",
"desc": "<p>A Node.js API was called in an unsupported manner, such as\n<code>Buffer.write(string, encoding, offset[, length])</code>.</p>\n<p><a id=\"ERR_OUT_OF_RANGE\"></a></p>\n",
"type": "module",
"displayName": "ERR_NO_LONGER_SUPPORTED"
},
{
"textRaw": "ERR_OUT_OF_RANGE",
"name": "err_out_of_range",
"desc": "<p>A given value is out of the accepted range.</p>\n<p><a id=\"ERR_REQUIRE_ESM\"></a></p>\n",
"type": "module",
"displayName": "ERR_OUT_OF_RANGE"
},
{
"textRaw": "ERR_REQUIRE_ESM",
"name": "err_require_esm",
"stability": 1,
"stabilityText": "Experimental",
"desc": "<p>An attempt was made to <code>require()</code> an <a href=\"esm.html\">ES6 module</a>.</p>\n<p><a id=\"ERR_SCRIPT_EXECUTION_INTERRUPTED\"></a></p>\n",
"type": "module",
"displayName": "ERR_REQUIRE_ESM"
},
{
"textRaw": "ERR_SCRIPT_EXECUTION_INTERRUPTED",
"name": "err_script_execution_interrupted",
"desc": "<p>Script execution was interrupted by <code>SIGINT</code> (For example, when Ctrl+C was\npressed).</p>\n<p><a id=\"ERR_SCRIPT_EXECUTION_TIMEOUT\"></a></p>\n",
"type": "module",
"displayName": "ERR_SCRIPT_EXECUTION_INTERRUPTED"
},
{
"textRaw": "ERR_SCRIPT_EXECUTION_TIMEOUT",
"name": "err_script_execution_timeout",
"desc": "<p>Script execution timed out, possibly due to bugs in the script being executed.</p>\n<p><a id=\"ERR_SERVER_ALREADY_LISTEN\"></a></p>\n",
"type": "module",
"displayName": "ERR_SCRIPT_EXECUTION_TIMEOUT"
},
{
"textRaw": "ERR_SERVER_ALREADY_LISTEN",
"name": "err_server_already_listen",
"desc": "<p>The <a href=\"net.html#net_server_listen\"><code>server.listen()</code></a> method was called while a <code>net.Server</code> was already\nlistening. This applies to all instances of <code>net.Server</code>, including HTTP, HTTPS,\nand HTTP/2 <code>Server</code> instances.</p>\n<p><a id=\"ERR_SERVER_NOT_RUNNING\"></a></p>\n",
"type": "module",
"displayName": "ERR_SERVER_ALREADY_LISTEN"
},
{
"textRaw": "ERR_SERVER_NOT_RUNNING",
"name": "err_server_not_running",
"desc": "<p>The <a href=\"net.html#net_server_close_callback\"><code>server.close()</code></a> method was called when a <code>net.Server</code> was not\nrunning. This applies to all instances of <code>net.Server</code>, including HTTP, HTTPS,\nand HTTP/2 <code>Server</code> instances.</p>\n<p><a id=\"ERR_SOCKET_ALREADY_BOUND\"></a></p>\n",
"type": "module",
"displayName": "ERR_SERVER_NOT_RUNNING"
},
{
"textRaw": "ERR_SOCKET_ALREADY_BOUND",
"name": "err_socket_already_bound",
"desc": "<p>An attempt was made to bind a socket that has already been bound.</p>\n<p><a id=\"ERR_SOCKET_BAD_BUFFER_SIZE\"></a></p>\n",
"type": "module",
"displayName": "ERR_SOCKET_ALREADY_BOUND"
},
{
"textRaw": "ERR_SOCKET_BAD_BUFFER_SIZE",
"name": "err_socket_bad_buffer_size",
"desc": "<p>An invalid (negative) size was passed for either the <code>recvBufferSize</code> or\n<code>sendBufferSize</code> options in <a href=\"dgram.html#dgram_dgram_createsocket_options_callback\"><code>dgram.createSocket()</code></a>.</p>\n<p><a id=\"ERR_SOCKET_BAD_PORT\"></a></p>\n",
"type": "module",
"displayName": "ERR_SOCKET_BAD_BUFFER_SIZE"
},
{
"textRaw": "ERR_SOCKET_BAD_PORT",
"name": "err_socket_bad_port",
"desc": "<p>An API function expecting a port &gt; 0 and &lt; 65536 received an invalid value.</p>\n<p><a id=\"ERR_SOCKET_BAD_TYPE\"></a></p>\n",
"type": "module",
"displayName": "ERR_SOCKET_BAD_PORT"
},
{
"textRaw": "ERR_SOCKET_BAD_TYPE",
"name": "err_socket_bad_type",
"desc": "<p>An API function expecting a socket type (<code>udp4</code> or <code>udp6</code>) received an invalid\nvalue.</p>\n<p><a id=\"ERR_SOCKET_BUFFER_SIZE\"></a></p>\n",
"type": "module",
"displayName": "ERR_SOCKET_BAD_TYPE"
},
{
"textRaw": "ERR_SOCKET_BUFFER_SIZE",
"name": "err_socket_buffer_size",
"desc": "<p>While using <a href=\"dgram.html#dgram_dgram_createsocket_options_callback\"><code>dgram.createSocket()</code></a>, the size of the receive or send <code>Buffer</code>\ncould not be determined.</p>\n<p><a id=\"ERR_SOCKET_CANNOT_SEND\"></a></p>\n",
"type": "module",
"displayName": "ERR_SOCKET_BUFFER_SIZE"
},
{
"textRaw": "ERR_SOCKET_CANNOT_SEND",
"name": "err_socket_cannot_send",
"desc": "<p>Data could be sent on a socket.</p>\n<p><a id=\"ERR_SOCKET_CLOSED\"></a></p>\n",
"type": "module",
"displayName": "ERR_SOCKET_CANNOT_SEND"
},
{
"textRaw": "ERR_SOCKET_CLOSED",
"name": "err_socket_closed",
"desc": "<p>An attempt was made to operate on an already closed socket.</p>\n<p><a id=\"ERR_SOCKET_DGRAM_NOT_RUNNING\"></a></p>\n",
"type": "module",
"displayName": "ERR_SOCKET_CLOSED"
},
{
"textRaw": "ERR_SOCKET_DGRAM_NOT_RUNNING",
"name": "err_socket_dgram_not_running",
"desc": "<p>A call was made and the UDP subsystem was not running.</p>\n<p><a id=\"ERR_STDERR_CLOSE\"></a></p>\n",
"type": "module",
"displayName": "ERR_SOCKET_DGRAM_NOT_RUNNING"
},
{
"textRaw": "ERR_STDERR_CLOSE",
"name": "err_stderr_close",
"desc": "<p>An attempt was made to close the <code>process.stderr</code> stream. By design, Node.js\ndoes not allow <code>stdout</code> or <code>stderr</code> streams to be closed by user code.</p>\n<p><a id=\"ERR_STDOUT_CLOSE\"></a></p>\n",
"type": "module",
"displayName": "ERR_STDERR_CLOSE"
},
{
"textRaw": "ERR_STDOUT_CLOSE",
"name": "err_stdout_close",
"desc": "<p>An attempt was made to close the <code>process.stdout</code> stream. By design, Node.js\ndoes not allow <code>stdout</code> or <code>stderr</code> streams to be closed by user code.</p>\n<p><a id=\"ERR_STREAM_CANNOT_PIPE\"></a></p>\n",
"type": "module",
"displayName": "ERR_STDOUT_CLOSE"
},
{
"textRaw": "ERR_STREAM_CANNOT_PIPE",
"name": "err_stream_cannot_pipe",
"desc": "<p>An attempt was made to call <a href=\"stream.html#stream_readable_pipe_destination_options\"><code>stream.pipe()</code></a> on a <a href=\"stream.html#stream_class_stream_writable\"><code>Writable</code></a> stream.</p>\n<p><a id=\"ERR_STREAM_DESTROYED\"></a></p>\n",
"type": "module",
"displayName": "ERR_STREAM_CANNOT_PIPE"
},
{
"textRaw": "ERR_STREAM_DESTROYED",
"name": "err_stream_destroyed",
"desc": "<p>A stream method was called that cannot complete because the stream was\ndestroyed using <code>stream.destroy()</code>.</p>\n<p><a id=\"ERR_STREAM_NULL_VALUES\"></a></p>\n",
"type": "module",
"displayName": "ERR_STREAM_DESTROYED"
},
{
"textRaw": "ERR_STREAM_NULL_VALUES",
"name": "err_stream_null_values",
"desc": "<p>An attempt was made to call <a href=\"stream.html#stream_writable_write_chunk_encoding_callback\"><code>stream.write()</code></a> with a <code>null</code> chunk.</p>\n<p><a id=\"ERR_STREAM_PREMATURE_CLOSE\"></a></p>\n",
"type": "module",
"displayName": "ERR_STREAM_NULL_VALUES"
},
{
"textRaw": "ERR_STREAM_PREMATURE_CLOSE",
"name": "err_stream_premature_close",
"desc": "<p>An error returned by <code>stream.finished()</code> and <code>stream.pipeline()</code>, when a stream\nor a pipeline ends non gracefully with no explicit error.</p>\n<p><a id=\"ERR_STREAM_PUSH_AFTER_EOF\"></a></p>\n",
"type": "module",
"displayName": "ERR_STREAM_PREMATURE_CLOSE"
},
{
"textRaw": "ERR_STREAM_PUSH_AFTER_EOF",
"name": "err_stream_push_after_eof",
"desc": "<p>An attempt was made to call <a href=\"stream.html#stream_readable_push_chunk_encoding\"><code>stream.push()</code></a> after a <code>null</code>(EOF) had been\npushed to the stream.</p>\n<p><a id=\"ERR_STREAM_READ_NOT_IMPLEMENTED\"></a></p>\n",
"type": "module",
"displayName": "ERR_STREAM_PUSH_AFTER_EOF"
},
{
"textRaw": "ERR_STREAM_READ_NOT_IMPLEMENTED",
"name": "err_stream_read_not_implemented",
"desc": "<p>An attempt was made to use a readable stream that did not implement\n<a href=\"stream.html#stream_readable_read_size_1\"><code>readable._read()</code></a>.</p>\n<p><a id=\"ERR_STREAM_UNSHIFT_AFTER_END_EVENT\"></a></p>\n",
"type": "module",
"displayName": "ERR_STREAM_READ_NOT_IMPLEMENTED"
},
{
"textRaw": "ERR_STREAM_UNSHIFT_AFTER_END_EVENT",
"name": "err_stream_unshift_after_end_event",
"desc": "<p>An attempt was made to call <a href=\"stream.html#stream_readable_unshift_chunk\"><code>stream.unshift()</code></a> after the <code>&#39;end&#39;</code> event was\nemitted.</p>\n<p><a id=\"ERR_STREAM_WRAP\"></a></p>\n",
"type": "module",
"displayName": "ERR_STREAM_UNSHIFT_AFTER_END_EVENT"
},
{
"textRaw": "ERR_STREAM_WRAP",
"name": "err_stream_wrap",
"desc": "<p>Prevents an abort if a string decoder was set on the Socket or if the decoder\nis in <code>objectMode</code>.</p>\n<p>Example</p>\n<pre><code class=\"lang-js\">const Socket = require(&#39;net&#39;).Socket;\nconst instance = new Socket();\n\ninstance.setEncoding(&#39;utf8&#39;);\n</code></pre>\n<p><a id=\"ERR_STREAM_WRITE_AFTER_END\"></a></p>\n",
"type": "module",
"displayName": "ERR_STREAM_WRAP"
},
{
"textRaw": "ERR_STREAM_WRITE_AFTER_END",
"name": "err_stream_write_after_end",
"desc": "<p>An attempt was made to call <a href=\"stream.html#stream_writable_write_chunk_encoding_callback\"><code>stream.write()</code></a> after <code>stream.end()</code> has been\ncalled.</p>\n<p><a id=\"ERR_STRING_TOO_LONG\"></a></p>\n",
"type": "module",
"displayName": "ERR_STREAM_WRITE_AFTER_END"
},
{
"textRaw": "ERR_STRING_TOO_LONG",
"name": "err_string_too_long",
"desc": "<p>An attempt has been made to create a string longer than the maximum allowed\nlength.</p>\n<p><a id=\"ERR_SYSTEM_ERROR\"></a></p>\n",
"type": "module",
"displayName": "ERR_STRING_TOO_LONG"
},
{
"textRaw": "ERR_SYSTEM_ERROR",
"name": "err_system_error",
"desc": "<p>An unspecified or non-specific system error has occurred within the Node.js\nprocess. The error object will have an <code>err.info</code> object property with\nadditional details.</p>\n<p><a id=\"ERR_TLS_CERT_ALTNAME_INVALID\"></a></p>\n",
"type": "module",
"displayName": "ERR_SYSTEM_ERROR"
},
{
"textRaw": "ERR_TLS_CERT_ALTNAME_INVALID",
"name": "err_tls_cert_altname_invalid",
"desc": "<p>While using TLS, the hostname/IP of the peer did not match any of the\n<code>subjectAltNames</code> in its certificate.</p>\n<p><a id=\"ERR_TLS_DH_PARAM_SIZE\"></a></p>\n",
"type": "module",
"displayName": "ERR_TLS_CERT_ALTNAME_INVALID"
},
{
"textRaw": "ERR_TLS_DH_PARAM_SIZE",
"name": "err_tls_dh_param_size",
"desc": "<p>While using TLS, the parameter offered for the Diffie-Hellman (<code>DH</code>)\nkey-agreement protocol is too small. By default, the key length must be greater\nthan or equal to 1024 bits to avoid vulnerabilities, even though it is strongly\nrecommended to use 2048 bits or larger for stronger security.</p>\n<p><a id=\"ERR_TLS_HANDSHAKE_TIMEOUT\"></a></p>\n",
"type": "module",
"displayName": "ERR_TLS_DH_PARAM_SIZE"
},
{
"textRaw": "ERR_TLS_HANDSHAKE_TIMEOUT",
"name": "err_tls_handshake_timeout",
"desc": "<p>A TLS/SSL handshake timed out. In this case, the server must also abort the\nconnection.</p>\n<p><a id=\"ERR_TLS_RENEGOTIATION_DISABLED\"></a></p>\n",
"type": "module",
"displayName": "ERR_TLS_HANDSHAKE_TIMEOUT"
},
{
"textRaw": "ERR_TLS_RENEGOTIATION_DISABLED",
"name": "err_tls_renegotiation_disabled",
"desc": "<p>An attempt was made to renegotiate TLS on a socket instance with TLS disabled.</p>\n<p><a id=\"ERR_TLS_REQUIRED_SERVER_NAME\"></a></p>\n",
"type": "module",
"displayName": "ERR_TLS_RENEGOTIATION_DISABLED"
},
{
"textRaw": "ERR_TLS_REQUIRED_SERVER_NAME",
"name": "err_tls_required_server_name",
"desc": "<p>While using TLS, the <code>server.addContext()</code> method was called without providing\na hostname in the first parameter.</p>\n<p><a id=\"ERR_TLS_SESSION_ATTACK\"></a></p>\n",
"type": "module",
"displayName": "ERR_TLS_REQUIRED_SERVER_NAME"
},
{
"textRaw": "ERR_TLS_SESSION_ATTACK",
"name": "err_tls_session_attack",
"desc": "<p>An excessive amount of TLS renegotiations is detected, which is a potential\nvector for denial-of-service attacks.</p>\n<p><a id=\"ERR_TLS_SNI_FROM_SERVER\"></a></p>\n",
"type": "module",
"displayName": "ERR_TLS_SESSION_ATTACK"
},
{
"textRaw": "ERR_TLS_SNI_FROM_SERVER",
"name": "err_tls_sni_from_server",
"desc": "<p>An attempt was made to issue Server Name Indication from a TLS server-side\nsocket, which is only valid from a client.</p>\n<p><a id=\"ERR_TRACE_EVENTS_CATEGORY_REQUIRED\"></a></p>\n",
"type": "module",
"displayName": "ERR_TLS_SNI_FROM_SERVER"
},
{
"textRaw": "ERR_TRACE_EVENTS_CATEGORY_REQUIRED",
"name": "err_trace_events_category_required",
"desc": "<p>The <code>trace_events.createTracing()</code> method requires at least one trace event\ncategory.</p>\n<p><a id=\"ERR_TRACE_EVENTS_UNAVAILABLE\"></a></p>\n",
"type": "module",
"displayName": "ERR_TRACE_EVENTS_CATEGORY_REQUIRED"
},
{
"textRaw": "ERR_TRACE_EVENTS_UNAVAILABLE",
"name": "err_trace_events_unavailable",
"desc": "<p>The <code>trace_events</code> module could not be loaded because Node.js was compiled with\nthe <code>--without-v8-platform</code> flag.</p>\n<p><a id=\"ERR_TRANSFORM_ALREADY_TRANSFORMING\"></a></p>\n",
"type": "module",
"displayName": "ERR_TRACE_EVENTS_UNAVAILABLE"
},
{
"textRaw": "ERR_TRANSFORM_ALREADY_TRANSFORMING",
"name": "err_transform_already_transforming",
"desc": "<p>A <code>Transform</code> stream finished while it was still transforming.</p>\n<p><a id=\"ERR_TRANSFORM_WITH_LENGTH_0\"></a></p>\n",
"type": "module",
"displayName": "ERR_TRANSFORM_ALREADY_TRANSFORMING"
},
{
"textRaw": "ERR_TRANSFORM_WITH_LENGTH_0",
"name": "err_transform_with_length_0",
"desc": "<p>A <code>Transform</code> stream finished with data still in the write buffer.</p>\n<p><a id=\"ERR_TTY_INIT_FAILED\"></a></p>\n",
"type": "module",
"displayName": "ERR_TRANSFORM_WITH_LENGTH_0"
},
{
"textRaw": "ERR_TTY_INIT_FAILED",
"name": "err_tty_init_failed",
"desc": "<p>The initialization of a TTY failed due to a system error.</p>\n<p><a id=\"ERR_UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET\"></a></p>\n",
"type": "module",
"displayName": "ERR_TTY_INIT_FAILED"
},
{
"textRaw": "ERR_UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET",
"name": "err_uncaught_exception_capture_already_set",
"desc": "<p><a href=\"process.html#process_process_setuncaughtexceptioncapturecallback_fn\"><code>process.setUncaughtExceptionCaptureCallback()</code></a> was called twice,\nwithout first resetting the callback to <code>null</code>.</p>\n<p>This error is designed to prevent accidentally overwriting a callback registered\nfrom another module.</p>\n<p><a id=\"ERR_UNESCAPED_CHARACTERS\"></a></p>\n",
"type": "module",
"displayName": "ERR_UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET"
},
{
"textRaw": "ERR_UNESCAPED_CHARACTERS",
"name": "err_unescaped_characters",
"desc": "<p>A string that contained unescaped characters was received.</p>\n<p><a id=\"ERR_UNHANDLED_ERROR\"></a></p>\n",
"type": "module",
"displayName": "ERR_UNESCAPED_CHARACTERS"
},
{
"textRaw": "ERR_UNHANDLED_ERROR",
"name": "err_unhandled_error",
"desc": "<p>An unhandled error occurred (for instance, when an <code>&#39;error&#39;</code> event is emitted\nby an <a href=\"events.html#events_class_eventemitter\"><code>EventEmitter</code></a> but an <code>&#39;error&#39;</code> handler is not registered).</p>\n<p><a id=\"ERR_UNKNOWN_BUILTIN_MODULE\"></a></p>\n",
"type": "module",
"displayName": "ERR_UNHANDLED_ERROR"
},
{
"textRaw": "ERR_UNKNOWN_BUILTIN_MODULE",
"name": "err_unknown_builtin_module",
"desc": "<p>Used to identify a specific kind of internal Node.js error that should not\ntypically be triggered by user code. Instances of this error point to an\ninternal bug within the Node.js binary itself.</p>\n<p><a id=\"ERR_UNKNOWN_CREDENTIAL\"></a></p>\n",
"type": "module",
"displayName": "ERR_UNKNOWN_BUILTIN_MODULE"
},
{
"textRaw": "ERR_UNKNOWN_CREDENTIAL",
"name": "err_unknown_credential",
"desc": "<p>A Unix group or user identifier that does not exist was passed.</p>\n<p><a id=\"ERR_UNKNOWN_ENCODING\"></a></p>\n",
"type": "module",
"displayName": "ERR_UNKNOWN_CREDENTIAL"
},
{
"textRaw": "ERR_UNKNOWN_ENCODING",
"name": "err_unknown_encoding",
"desc": "<p>An invalid or unknown encoding option was passed to an API.</p>\n<p><a id=\"ERR_UNKNOWN_FILE_EXTENSION\"></a></p>\n",
"type": "module",
"displayName": "ERR_UNKNOWN_ENCODING"
},
{
"textRaw": "ERR_UNKNOWN_FILE_EXTENSION",
"name": "err_unknown_file_extension",
"stability": 1,
"stabilityText": "Experimental",
"desc": "<p>An attempt was made to load a module with an unknown or unsupported file\nextension.</p>\n<p><a id=\"ERR_UNKNOWN_MODULE_FORMAT\"></a></p>\n",
"type": "module",
"displayName": "ERR_UNKNOWN_FILE_EXTENSION"
},
{
"textRaw": "ERR_UNKNOWN_MODULE_FORMAT",
"name": "err_unknown_module_format",
"stability": 1,
"stabilityText": "Experimental",
"desc": "<p>An attempt was made to load a module with an unknown or unsupported format.</p>\n<p><a id=\"ERR_UNKNOWN_SIGNAL\"></a></p>\n",
"type": "module",
"displayName": "ERR_UNKNOWN_MODULE_FORMAT"
},
{
"textRaw": "ERR_UNKNOWN_SIGNAL",
"name": "err_unknown_signal",
"desc": "<p>An invalid or unknown process signal was passed to an API expecting a valid\nsignal (such as <a href=\"child_process.html#child_process_subprocess_kill_signal\"><code>subprocess.kill()</code></a>).</p>\n<p><a id=\"ERR_UNKNOWN_STDIN_TYPE\"></a></p>\n",
"type": "module",
"displayName": "ERR_UNKNOWN_SIGNAL"
},
{
"textRaw": "ERR_UNKNOWN_STDIN_TYPE",
"name": "err_unknown_stdin_type",
"desc": "<p>An attempt was made to launch a Node.js process with an unknown <code>stdin</code> file\ntype. This error is usually an indication of a bug within Node.js itself,\nalthough it is possible for user code to trigger it.</p>\n<p><a id=\"ERR_UNKNOWN_STREAM_TYPE\"></a></p>\n",
"type": "module",
"displayName": "ERR_UNKNOWN_STDIN_TYPE"
},
{
"textRaw": "ERR_UNKNOWN_STREAM_TYPE",
"name": "err_unknown_stream_type",
"desc": "<p>An attempt was made to launch a Node.js process with an unknown <code>stdout</code> or\n<code>stderr</code> file type. This error is usually an indication of a bug within Node.js\nitself, although it is possible for user code to trigger it.</p>\n<p><a id=\"ERR_V8BREAKITERATOR\"></a></p>\n",
"type": "module",
"displayName": "ERR_UNKNOWN_STREAM_TYPE"
},
{
"textRaw": "ERR_V8BREAKITERATOR",
"name": "err_v8breakiterator",
"desc": "<p>The V8 <code>BreakIterator</code> API was used but the full ICU data set is not installed.</p>\n<p><a id=\"ERR_VALID_PERFORMANCE_ENTRY_TYPE\"></a></p>\n",
"type": "module",
"displayName": "ERR_V8BREAKITERATOR"
},
{
"textRaw": "ERR_VALID_PERFORMANCE_ENTRY_TYPE",
"name": "err_valid_performance_entry_type",
"desc": "<p>While using the Performance Timing API (<code>perf_hooks</code>), no valid performance\nentry types were found.</p>\n<p><a id=\"ERR_VALUE_OUT_OF_RANGE\"></a></p>\n",
"type": "module",
"displayName": "ERR_VALID_PERFORMANCE_ENTRY_TYPE"
},
{
"textRaw": "ERR_VALUE_OUT_OF_RANGE",
"name": "err_value_out_of_range",
"desc": "<p>Superseded by <code>ERR_OUT_OF_RANGE</code>.</p>\n<p><a id=\"ERR_VM_MODULE_ALREADY_LINKED\"></a></p>\n",
"type": "module",
"displayName": "ERR_VALUE_OUT_OF_RANGE"
},
{
"textRaw": "ERR_VM_MODULE_ALREADY_LINKED",
"name": "err_vm_module_already_linked",
"desc": "<p>The module attempted to be linked is not eligible for linking, because of one of\nthe following reasons:</p>\n<ul>\n<li>It has already been linked (<code>linkingStatus</code> is <code>&#39;linked&#39;</code>)</li>\n<li>It is being linked (<code>linkingStatus</code> is <code>&#39;linking&#39;</code>)</li>\n<li>Linking has failed for this module (<code>linkingStatus</code> is <code>&#39;errored&#39;</code>)</li>\n</ul>\n<p><a id=\"ERR_VM_MODULE_DIFFERENT_CONTEXT\"></a></p>\n",
"type": "module",
"displayName": "ERR_VM_MODULE_ALREADY_LINKED"
},
{
"textRaw": "ERR_VM_MODULE_DIFFERENT_CONTEXT",
"name": "err_vm_module_different_context",
"desc": "<p>The module being returned from the linker function is from a different context\nthan the parent module. Linked modules must share the same context.</p>\n<p><a id=\"ERR_VM_MODULE_LINKING_ERRORED\"></a></p>\n",
"type": "module",
"displayName": "ERR_VM_MODULE_DIFFERENT_CONTEXT"
},
{
"textRaw": "ERR_VM_MODULE_LINKING_ERRORED",
"name": "err_vm_module_linking_errored",
"desc": "<p>The linker function returned a module for which linking has failed.</p>\n<p><a id=\"ERR_VM_MODULE_NOT_LINKED\"></a></p>\n",
"type": "module",
"displayName": "ERR_VM_MODULE_LINKING_ERRORED"
},
{
"textRaw": "ERR_VM_MODULE_NOT_LINKED",
"name": "err_vm_module_not_linked",
"desc": "<p>The module must be successfully linked before instantiation.</p>\n<p><a id=\"ERR_VM_MODULE_NOT_MODULE\"></a></p>\n",
"type": "module",
"displayName": "ERR_VM_MODULE_NOT_LINKED"
},
{
"textRaw": "ERR_VM_MODULE_NOT_MODULE",
"name": "err_vm_module_not_module",
"desc": "<p>The fulfilled value of a linking promise is not a <code>vm.Module</code> object.</p>\n<p><a id=\"ERR_VM_MODULE_STATUS\"></a></p>\n",
"type": "module",
"displayName": "ERR_VM_MODULE_NOT_MODULE"
},
{
"textRaw": "ERR_VM_MODULE_STATUS",
"name": "err_vm_module_status",
"desc": "<p>The current module&#39;s status does not allow for this operation. The specific\nmeaning of the error depends on the specific function.</p>\n<p><a id=\"ERR_WORKER_PATH\"></a></p>\n",
"type": "module",
"displayName": "ERR_VM_MODULE_STATUS"
},
{
"textRaw": "ERR_WORKER_PATH",
"name": "err_worker_path",
"desc": "<p>The path for the main script of a worker is neither an absolute path\nnor a relative path starting with <code>./</code> or <code>../</code>.</p>\n<p><a id=\"ERR_WORKER_UNSERIALIZABLE_ERROR\"></a></p>\n",
"type": "module",
"displayName": "ERR_WORKER_PATH"
},
{
"textRaw": "ERR_WORKER_UNSERIALIZABLE_ERROR",
"name": "err_worker_unserializable_error",
"desc": "<p>All attempts at serializing an uncaught exception from a worker thread failed.</p>\n<p><a id=\"ERR_WORKER_UNSUPPORTED_EXTENSION\"></a></p>\n",
"type": "module",
"displayName": "ERR_WORKER_UNSERIALIZABLE_ERROR"
},
{
"textRaw": "ERR_WORKER_UNSUPPORTED_EXTENSION",
"name": "err_worker_unsupported_extension",
"desc": "<p>The pathname used for the main script of a worker has an\nunknown file extension.</p>\n<p><a id=\"ERR_ZLIB_INITIALIZATION_FAILED\"></a></p>\n",
"type": "module",
"displayName": "ERR_WORKER_UNSUPPORTED_EXTENSION"
},
{
"textRaw": "ERR_ZLIB_INITIALIZATION_FAILED",
"name": "err_zlib_initialization_failed",
"desc": "<p>Creation of a <a href=\"zlib.html\"><code>zlib</code></a> object failed due to incorrect configuration.</p>\n",
"type": "module",
"displayName": "ERR_ZLIB_INITIALIZATION_FAILED"
}
],
"type": "misc",
"displayName": "Node.js Error Codes"
}
],
"classes": [
{
"textRaw": "Class: Error",
"type": "class",
"name": "Error",
"desc": "<p>A generic JavaScript <code>Error</code> object that does not denote any specific\ncircumstance of why the error occurred. <code>Error</code> objects capture a &quot;stack trace&quot;\ndetailing the point in the code at which the <code>Error</code> was instantiated, and may\nprovide a text description of the error.</p>\n<p>For crypto only, <code>Error</code> objects will include the OpenSSL error stack in a\nseparate property called <code>opensslErrorStack</code> if it is available when the error\nis thrown.</p>\n<p>All errors generated by Node.js, including all System and JavaScript errors,\nwill either be instances of, or inherit from, the <code>Error</code> class.</p>\n",
"methods": [
{
"textRaw": "Error.captureStackTrace(targetObject[, constructorOpt])",
"type": "method",
"name": "captureStackTrace",
"signatures": [
{
"params": [
{
"textRaw": "`targetObject` {Object} ",
"name": "targetObject",
"type": "Object"
},
{
"textRaw": "`constructorOpt` {Function} ",
"name": "constructorOpt",
"type": "Function",
"optional": true
}
]
},
{
"params": [
{
"name": "targetObject"
},
{
"name": "constructorOpt",
"optional": true
}
]
}
],
"desc": "<p>Creates a <code>.stack</code> property on <code>targetObject</code>, which when accessed returns\na string representing the location in the code at which\n<code>Error.captureStackTrace()</code> was called.</p>\n<pre><code class=\"lang-js\">const myObject = {};\nError.captureStackTrace(myObject);\nmyObject.stack; // similar to `new Error().stack`\n</code></pre>\n<p>The first line of the trace will be prefixed with\n<code>${myObject.name}: ${myObject.message}</code>.</p>\n<p>The optional <code>constructorOpt</code> argument accepts a function. If given, all frames\nabove <code>constructorOpt</code>, including <code>constructorOpt</code>, will be omitted from the\ngenerated stack trace.</p>\n<p>The <code>constructorOpt</code> argument is useful for hiding implementation\ndetails of error generation from an end user. For instance:</p>\n<pre><code class=\"lang-js\">function MyError() {\n Error.captureStackTrace(this, MyError);\n}\n\n// Without passing MyError to captureStackTrace, the MyError\n// frame would show up in the .stack property. By passing\n// the constructor, we omit that frame, and retain all frames below it.\nnew MyError().stack;\n</code></pre>\n"
}
],
"properties": [
{
"textRaw": "`stackTraceLimit` {number} ",
"type": "number",
"name": "stackTraceLimit",
"desc": "<p>The <code>Error.stackTraceLimit</code> property specifies the number of stack frames\ncollected by a stack trace (whether generated by <code>new Error().stack</code> or\n<code>Error.captureStackTrace(obj)</code>).</p>\n<p>The default value is <code>10</code> but may be set to any valid JavaScript number. Changes\nwill affect any stack trace captured <em>after</em> the value has been changed.</p>\n<p>If set to a non-number value, or set to a negative number, stack traces will\nnot capture any frames.</p>\n"
},
{
"textRaw": "`code` {string} ",
"type": "string",
"name": "code",
"desc": "<p>The <code>error.code</code> property is a string label that identifies the kind of error.\nSee <a href=\"#nodejs-error-codes\">Node.js Error Codes</a> for details about specific codes.</p>\n"
},
{
"textRaw": "`message` {string} ",
"type": "string",
"name": "message",
"desc": "<p>The <code>error.message</code> property is the string description of the error as set by\ncalling <code>new Error(message)</code>. The <code>message</code> passed to the constructor will also\nappear in the first line of the stack trace of the <code>Error</code>, however changing\nthis property after the <code>Error</code> object is created <em>may not</em> change the first\nline of the stack trace (for example, when <code>error.stack</code> is read before this\nproperty is changed).</p>\n<pre><code class=\"lang-js\">const err = new Error(&#39;The message&#39;);\nconsole.error(err.message);\n// Prints: The message\n</code></pre>\n"
},
{
"textRaw": "`stack` {string} ",
"type": "string",
"name": "stack",
"desc": "<p>The <code>error.stack</code> property is a string describing the point in the code at which\nthe <code>Error</code> was instantiated.</p>\n<pre><code class=\"lang-txt\">Error: Things keep happening!\n at /home/gbusey/file.js:525:2\n at Frobnicator.refrobulate (/home/gbusey/business-logic.js:424:21)\n at Actor.&lt;anonymous&gt; (/home/gbusey/actors.js:400:8)\n at increaseSynergy (/home/gbusey/actors.js:701:6)\n</code></pre>\n<p>The first line is formatted as <code>&lt;error class name&gt;: &lt;error message&gt;</code>, and\nis followed by a series of stack frames (each line beginning with &quot;at &quot;).\nEach frame describes a call site within the code that lead to the error being\ngenerated. V8 attempts to display a name for each function (by variable name,\nfunction name, or object method name), but occasionally it will not be able to\nfind a suitable name. If V8 cannot determine a name for the function, only\nlocation information will be displayed for that frame. Otherwise, the\ndetermined function name will be displayed with location information appended\nin parentheses.</p>\n<p>Frames are only generated for JavaScript functions. If, for example, execution\nsynchronously passes through a C++ addon function called <code>cheetahify</code> which\nitself calls a JavaScript function, the frame representing the <code>cheetahify</code> call\nwill not be present in the stack traces:</p>\n<pre><code class=\"lang-js\">const cheetahify = require(&#39;./native-binding.node&#39;);\n\nfunction makeFaster() {\n // cheetahify *synchronously* calls speedy.\n cheetahify(function speedy() {\n throw new Error(&#39;oh no!&#39;);\n });\n}\n\nmakeFaster();\n// will throw:\n// /home/gbusey/file.js:6\n// throw new Error(&#39;oh no!&#39;);\n// ^\n// Error: oh no!\n// at speedy (/home/gbusey/file.js:6:11)\n// at makeFaster (/home/gbusey/file.js:5:3)\n// at Object.&lt;anonymous&gt; (/home/gbusey/file.js:10:1)\n// at Module._compile (module.js:456:26)\n// at Object.Module._extensions..js (module.js:474:10)\n// at Module.load (module.js:356:32)\n// at Function.Module._load (module.js:312:12)\n// at Function.Module.runMain (module.js:497:10)\n// at startup (node.js:119:16)\n// at node.js:906:3\n</code></pre>\n<p>The location information will be one of:</p>\n<ul>\n<li><code>native</code>, if the frame represents a call internal to V8 (as in <code>[].forEach</code>).</li>\n<li><code>plain-filename.js:line:column</code>, if the frame represents a call internal\n to Node.js.</li>\n<li><code>/absolute/path/to/file.js:line:column</code>, if the frame represents a call in\na user program, or its dependencies.</li>\n</ul>\n<p>The string representing the stack trace is lazily generated when the\n<code>error.stack</code> property is <strong>accessed</strong>.</p>\n<p>The number of frames captured by the stack trace is bounded by the smaller of\n<code>Error.stackTraceLimit</code> or the number of available frames on the current event\nloop tick.</p>\n<p>System-level errors are generated as augmented <code>Error</code> instances, which are\ndetailed <a href=\"#errors_system_errors\">here</a>.</p>\n"
}
],
"signatures": [
{
"params": [
{
"textRaw": "`message` {string} ",
"name": "message",
"type": "string"
}
],
"desc": "<p>Creates a new <code>Error</code> object and sets the <code>error.message</code> property to the\nprovided text message. If an object is passed as <code>message</code>, the text message\nis generated by calling <code>message.toString()</code>. The <code>error.stack</code> property will\nrepresent the point in the code at which <code>new Error()</code> was called. Stack traces\nare dependent on <a href=\"https://github.com/v8/v8/wiki/Stack-Trace-API\">V8&#39;s stack trace API</a>. Stack traces extend only to either\n(a) the beginning of <em>synchronous code execution</em>, or (b) the number of frames\ngiven by the property <code>Error.stackTraceLimit</code>, whichever is smaller.</p>\n"
},
{
"params": [
{
"name": "message"
}
],
"desc": "<p>Creates a new <code>Error</code> object and sets the <code>error.message</code> property to the\nprovided text message. If an object is passed as <code>message</code>, the text message\nis generated by calling <code>message.toString()</code>. The <code>error.stack</code> property will\nrepresent the point in the code at which <code>new Error()</code> was called. Stack traces\nare dependent on <a href=\"https://github.com/v8/v8/wiki/Stack-Trace-API\">V8&#39;s stack trace API</a>. Stack traces extend only to either\n(a) the beginning of <em>synchronous code execution</em>, or (b) the number of frames\ngiven by the property <code>Error.stackTraceLimit</code>, whichever is smaller.</p>\n"
}
]
},
{
"textRaw": "Class: AssertionError",
"type": "class",
"name": "AssertionError",
"desc": "<p>A subclass of <code>Error</code> that indicates the failure of an assertion. For details,\nsee <a href=\"assert.html#assert_class_assert_assertionerror\"><code>Class: assert.AssertionError</code></a>.</p>\n"
},
{
"textRaw": "Class: RangeError",
"type": "class",
"name": "RangeError",
"desc": "<p>A subclass of <code>Error</code> that indicates that a provided argument was not within the\nset or range of acceptable values for a function; whether that is a numeric\nrange, or outside the set of options for a given function parameter.</p>\n<pre><code class=\"lang-js\">require(&#39;net&#39;).connect(-1);\n// throws &quot;RangeError: &quot;port&quot; option should be &gt;= 0 and &lt; 65536: -1&quot;\n</code></pre>\n<p>Node.js will generate and throw <code>RangeError</code> instances <em>immediately</em> as a form\nof argument validation.</p>\n"
},
{
"textRaw": "Class: ReferenceError",
"type": "class",
"name": "ReferenceError",
"desc": "<p>A subclass of <code>Error</code> that indicates that an attempt is being made to access a\nvariable that is not defined. Such errors commonly indicate typos in code, or\nan otherwise broken program.</p>\n<p>While client code may generate and propagate these errors, in practice, only V8\nwill do so.</p>\n<pre><code class=\"lang-js\">doesNotExist;\n// throws ReferenceError, doesNotExist is not a variable in this program.\n</code></pre>\n<p>Unless an application is dynamically generating and running code,\n<code>ReferenceError</code> instances should always be considered a bug in the code\nor its dependencies.</p>\n"
},
{
"textRaw": "Class: SyntaxError",
"type": "class",
"name": "SyntaxError",
"desc": "<p>A subclass of <code>Error</code> that indicates that a program is not valid JavaScript.\nThese errors may only be generated and propagated as a result of code\nevaluation. Code evaluation may happen as a result of <code>eval</code>, <code>Function</code>,\n<code>require</code>, or <a href=\"vm.html\">vm</a>. These errors are almost always indicative of a broken\nprogram.</p>\n<pre><code class=\"lang-js\">try {\n require(&#39;vm&#39;).runInThisContext(&#39;binary ! isNotOk&#39;);\n} catch (err) {\n // err will be a SyntaxError\n}\n</code></pre>\n<p><code>SyntaxError</code> instances are unrecoverable in the context that created them –\nthey may only be caught by other contexts.</p>\n"
},
{
"textRaw": "Class: TypeError",
"type": "class",
"name": "TypeError",
"desc": "<p>A subclass of <code>Error</code> that indicates that a provided argument is not an\nallowable type. For example, passing a function to a parameter which expects a\nstring would be considered a <code>TypeError</code>.</p>\n<pre><code class=\"lang-js\">require(&#39;url&#39;).parse(() =&gt; { });\n// throws TypeError, since it expected a string\n</code></pre>\n<p>Node.js will generate and throw <code>TypeError</code> instances <em>immediately</em> as a form\nof argument validation.</p>\n"
}
]
},
{
"textRaw": "Global Objects",
"name": "Global Objects",
"introduced_in": "v0.10.0",
"type": "misc",
"desc": "<p>These objects are available in all modules. The following variables may appear\nto be global but are not. They exist only in the scope of modules, see the\n<a href=\"modules.html\">module system documentation</a>:</p>\n<ul>\n<li><a href=\"modules.html#modules_dirname\"><code>__dirname</code></a></li>\n<li><a href=\"modules.html#modules_filename\"><code>__filename</code></a></li>\n<li><a href=\"modules.html#modules_exports\"><code>exports</code></a></li>\n<li><a href=\"modules.html#modules_module\"><code>module</code></a></li>\n<li><a href=\"modules.html#modules_require\"><code>require()</code></a></li>\n</ul>\n<p>The objects listed here are specific to Node.js. There are a number of\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects\">built-in objects</a> that are part of the JavaScript language itself, which are\nalso globally accessible.</p>\n",
"globals": [
{
"textRaw": "Class: Buffer",
"type": "global",
"name": "Buffer",
"meta": {
"added": [
"v0.1.103"
],
"changes": []
},
"desc": "<ul>\n<li>{Function}</li>\n</ul>\n<p>Used to handle binary data. See the <a href=\"buffer.html\">buffer section</a>.</p>\n"
},
{
"textRaw": "clearImmediate(immediateObject)",
"type": "global",
"name": "clearImmediate",
"meta": {
"added": [
"v0.9.1"
],
"changes": []
},
"desc": "<p><a href=\"timers.html#timers_clearimmediate_immediate\"><code>clearImmediate</code></a> is described in the <a href=\"timers.html\">timers</a> section.</p>\n"
},
{
"textRaw": "clearInterval(intervalObject)",
"type": "global",
"name": "clearInterval",
"meta": {
"added": [
"v0.0.1"
],
"changes": []
},
"desc": "<p><a href=\"timers.html#timers_clearinterval_timeout\"><code>clearInterval</code></a> is described in the <a href=\"timers.html\">timers</a> section.</p>\n"
},
{
"textRaw": "clearTimeout(timeoutObject)",
"type": "global",
"name": "clearTimeout",
"meta": {
"added": [
"v0.0.1"
],
"changes": []
},
"desc": "<p><a href=\"timers.html#timers_cleartimeout_timeout\"><code>clearTimeout</code></a> is described in the <a href=\"timers.html\">timers</a> section.</p>\n"
},
{
"textRaw": "console",
"name": "console",
"meta": {
"added": [
"v0.1.100"
],
"changes": []
},
"type": "global",
"desc": "<ul>\n<li>{Object}</li>\n</ul>\n<p>Used to print to stdout and stderr. See the <a href=\"console.html\"><code>console</code></a> section.</p>\n"
},
{
"textRaw": "global",
"name": "global",
"meta": {
"added": [
"v0.1.27"
],
"changes": []
},
"type": "global",
"desc": "<ul>\n<li>{Object} The global namespace object.</li>\n</ul>\n<p>In browsers, the top-level scope is the global scope. This means that\nwithin the browser <code>var something</code> will define a new global variable. In\nNode.js this is different. The top-level scope is not the global scope;\n<code>var something</code> inside a Node.js module will be local to that module.</p>\n"
},
{
"textRaw": "process",
"name": "process",
"meta": {
"added": [
"v0.1.7"
],
"changes": []
},
"type": "global",
"desc": "<ul>\n<li>{Object}</li>\n</ul>\n<p>The process object. See the <a href=\"process.html#process_process\"><code>process</code> object</a> section.</p>\n"
},
{
"textRaw": "setImmediate(callback[, ...args])",
"type": "global",
"name": "setImmediate",
"meta": {
"added": [
"v0.9.1"
],
"changes": []
},
"desc": "<p><a href=\"timers.html#timers_setimmediate_callback_args\"><code>setImmediate</code></a> is described in the <a href=\"timers.html\">timers</a> section.</p>\n"
},
{
"textRaw": "setInterval(callback, delay[, ...args])",
"type": "global",
"name": "setInterval",
"meta": {
"added": [
"v0.0.1"
],
"changes": []
},
"desc": "<p><a href=\"timers.html#timers_setinterval_callback_delay_args\"><code>setInterval</code></a> is described in the <a href=\"timers.html\">timers</a> section.</p>\n"
},
{
"textRaw": "setTimeout(callback, delay[, ...args])",
"type": "global",
"name": "setTimeout",
"meta": {
"added": [
"v0.0.1"
],
"changes": []
},
"desc": "<p><a href=\"timers.html#timers_settimeout_callback_delay_args\"><code>setTimeout</code></a> is described in the <a href=\"timers.html\">timers</a> section.</p>\n"
},
{
"textRaw": "URL",
"name": "URL",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"type": "global",
"desc": "<p>The WHATWG <code>URL</code> class. See the <a href=\"url.html#url_class_url\"><code>URL</code></a> section.</p>\n"
},
{
"textRaw": "URLSearchParams",
"name": "URLSearchParams",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"type": "global",
"desc": "<p>The WHATWG <code>URLSearchParams</code> class. See the <a href=\"url.html#url_class_urlsearchparams\"><code>URLSearchParams</code></a> section.</p>\n"
}
],
"miscs": [
{
"textRaw": "\\_\\_dirname",
"name": "\\_\\_dirname",
"desc": "<p>This variable may appear to be global but is not. See <a href=\"modules.html#modules_dirname\"><code>__dirname</code></a>.</p>\n",
"type": "misc",
"displayName": "\\_\\_dirname"
},
{
"textRaw": "\\_\\_filename",
"name": "\\_\\_filename",
"desc": "<p>This variable may appear to be global but is not. See <a href=\"modules.html#modules_filename\"><code>__filename</code></a>.</p>\n",
"type": "misc",
"displayName": "\\_\\_filename"
},
{
"textRaw": "exports",
"name": "exports",
"desc": "<p>This variable may appear to be global but is not. See <a href=\"modules.html#modules_exports\"><code>exports</code></a>.</p>\n",
"type": "misc",
"displayName": "exports"
},
{
"textRaw": "module",
"name": "module",
"desc": "<p>This variable may appear to be global but is not. See <a href=\"modules.html#modules_module\"><code>module</code></a>.</p>\n",
"type": "misc",
"displayName": "module"
}
],
"methods": [
{
"textRaw": "require()",
"type": "method",
"name": "require",
"desc": "<p>This variable may appear to be global but is not. See <a href=\"modules.html#modules_require\"><code>require()</code></a>.</p>\n",
"signatures": [
{
"params": []
}
]
}
]
},
{
"textRaw": "Internationalization Support",
"name": "Internationalization Support",
"introduced_in": "v8.2.0",
"type": "misc",
"desc": "<p>Node.js has many features that make it easier to write internationalized\nprograms. Some of them are:</p>\n<ul>\n<li>Locale-sensitive or Unicode-aware functions in the <a href=\"https://tc39.github.io/ecma262/\">ECMAScript Language\nSpecification</a>:<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize\"><code>String.prototype.normalize()</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase\"><code>String.prototype.toLowerCase()</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase\"><code>String.prototype.toUpperCase()</code></a></li>\n</ul>\n</li>\n<li>All functionality described in the <a href=\"https://tc39.github.io/ecma402/\">ECMAScript Internationalization API\nSpecification</a> (aka ECMA-402):<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl\"><code>Intl</code></a> object</li>\n<li>Locale-sensitive methods like <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare\"><code>String.prototype.localeCompare()</code></a> and\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString\"><code>Date.prototype.toLocaleString()</code></a></li>\n</ul>\n</li>\n<li>The <a href=\"url.html#url_the_whatwg_url_api\">WHATWG URL parser</a>&#39;s <a href=\"https://en.wikipedia.org/wiki/Internationalized_domain_name\">internationalized domain names</a> (IDNs) support</li>\n<li><a href=\"buffer.html#buffer_buffer_transcode_source_fromenc_toenc\"><code>require(&#39;buffer&#39;).transcode()</code></a></li>\n<li>More accurate <a href=\"repl.html#repl_repl\">REPL</a> line editing</li>\n<li><a href=\"util.html#util_class_util_textdecoder\"><code>require(&#39;util&#39;).TextDecoder</code></a></li>\n<li><a href=\"https://github.com/tc39/proposal-regexp-unicode-property-escapes\"><code>RegExp</code> Unicode Property Escapes</a></li>\n</ul>\n<p>Node.js (and its underlying V8 engine) uses <a href=\"http://icu-project.org/\">ICU</a> to implement these features\nin native C/C++ code. However, some of them require a very large ICU data file\nin order to support all locales of the world. Because it is expected that most\nNode.js users will make use of only a small portion of ICU functionality, only\na subset of the full ICU data set is provided by Node.js by default. Several\noptions are provided for customizing and expanding the ICU data set either when\nbuilding or running Node.js.</p>\n",
"miscs": [
{
"textRaw": "Options for building Node.js",
"name": "options_for_building_node.js",
"desc": "<p>To control how ICU is used in Node.js, four <code>configure</code> options are available\nduring compilation. Additional details on how to compile Node.js are documented\nin <a href=\"https://github.com/nodejs/node/blob/master/BUILDING.md\">BUILDING.md</a>.</p>\n<ul>\n<li><code>--with-intl=none</code>/<code>--without-intl</code></li>\n<li><code>--with-intl=system-icu</code></li>\n<li><code>--with-intl=small-icu</code> (default)</li>\n<li><code>--with-intl=full-icu</code></li>\n</ul>\n<p>An overview of available Node.js and JavaScript features for each <code>configure</code>\noption:</p>\n<table>\n<thead>\n<tr>\n<th></th>\n<th><code>none</code></th>\n<th><code>system-icu</code></th>\n<th><code>small-icu</code></th>\n<th><code>full-icu</code></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize\"><code>String.prototype.normalize()</code></a></td>\n<td>none (function is no-op)</td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n<tr>\n<td><code>String.prototype.to*Case()</code></td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl\"><code>Intl</code></a></td>\n<td>none (object does not exist)</td>\n<td>partial/full (depends on OS)</td>\n<td>partial (English-only)</td>\n<td>full</td>\n</tr>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare\"><code>String.prototype.localeCompare()</code></a></td>\n<td>partial (not locale-aware)</td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n<tr>\n<td><code>String.prototype.toLocale*Case()</code></td>\n<td>partial (not locale-aware)</td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString\"><code>Number.prototype.toLocaleString()</code></a></td>\n<td>partial (not locale-aware)</td>\n<td>partial/full (depends on OS)</td>\n<td>partial (English-only)</td>\n<td>full</td>\n</tr>\n<tr>\n<td><code>Date.prototype.toLocale*String()</code></td>\n<td>partial (not locale-aware)</td>\n<td>partial/full (depends on OS)</td>\n<td>partial (English-only)</td>\n<td>full</td>\n</tr>\n<tr>\n<td><a href=\"url.html#url_the_whatwg_url_api\">WHATWG URL Parser</a></td>\n<td>partial (no IDN support)</td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n<tr>\n<td><a href=\"buffer.html#buffer_buffer_transcode_source_fromenc_toenc\"><code>require(&#39;buffer&#39;).transcode()</code></a></td>\n<td>none (function does not exist)</td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n<tr>\n<td><a href=\"repl.html#repl_repl\">REPL</a></td>\n<td>partial (inaccurate line editing)</td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n<tr>\n<td><a href=\"util.html#util_class_util_textdecoder\"><code>require(&#39;util&#39;).TextDecoder</code></a></td>\n<td>partial (basic encodings support)</td>\n<td>partial/full (depends on OS)</td>\n<td>partial (Unicode-only)</td>\n<td>full</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/tc39/proposal-regexp-unicode-property-escapes\"><code>RegExp</code> Unicode Property Escapes</a></td>\n<td>none (invalid <code>RegExp</code> error)</td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n</tbody>\n</table>\n<p>The &quot;(not locale-aware)&quot; designation denotes that the function carries out its\noperation just like the non-<code>Locale</code> version of the function, if one\nexists. For example, under <code>none</code> mode, <code>Date.prototype.toLocaleString()</code>&#39;s\noperation is identical to that of <code>Date.prototype.toString()</code>.</p>\n",
"modules": [
{
"textRaw": "Disable all internationalization features (`none`)",
"name": "disable_all_internationalization_features_(`none`)",
"desc": "<p>If this option is chosen, most internationalization features mentioned above\nwill be <strong>unavailable</strong> in the resulting <code>node</code> binary.</p>\n",
"type": "module",
"displayName": "Disable all internationalization features (`none`)"
},
{
"textRaw": "Build with a pre-installed ICU (`system-icu`)",
"name": "build_with_a_pre-installed_icu_(`system-icu`)",
"desc": "<p>Node.js can link against an ICU build already installed on the system. In fact,\nmost Linux distributions already come with ICU installed, and this option would\nmake it possible to reuse the same set of data used by other components in the\nOS.</p>\n<p>Functionalities that only require the ICU library itself, such as\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize\"><code>String.prototype.normalize()</code></a> and the <a href=\"url.html#url_the_whatwg_url_api\">WHATWG URL parser</a>, are fully\nsupported under <code>system-icu</code>. Features that require ICU locale data in\naddition, such as <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat\"><code>Intl.DateTimeFormat</code></a> <em>may</em> be fully or partially\nsupported, depending on the completeness of the ICU data installed on the\nsystem.</p>\n",
"type": "module",
"displayName": "Build with a pre-installed ICU (`system-icu`)"
},
{
"textRaw": "Embed a limited set of ICU data (`small-icu`)",
"name": "embed_a_limited_set_of_icu_data_(`small-icu`)",
"desc": "<p>This option makes the resulting binary link against the ICU library statically,\nand includes a subset of ICU data (typically only the English locale) within\nthe <code>node</code> executable.</p>\n<p>Functionalities that only require the ICU library itself, such as\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize\"><code>String.prototype.normalize()</code></a> and the <a href=\"url.html#url_the_whatwg_url_api\">WHATWG URL parser</a>, are fully\nsupported under <code>small-icu</code>. Features that require ICU locale data in addition,\nsuch as <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat\"><code>Intl.DateTimeFormat</code></a>, generally only work with the English locale:</p>\n<pre><code class=\"lang-js\">const january = new Date(9e8);\nconst english = new Intl.DateTimeFormat(&#39;en&#39;, { month: &#39;long&#39; });\nconst spanish = new Intl.DateTimeFormat(&#39;es&#39;, { month: &#39;long&#39; });\n\nconsole.log(english.format(january));\n// Prints &quot;January&quot;\nconsole.log(spanish.format(january));\n// Prints &quot;M01&quot; on small-icu\n// Should print &quot;enero&quot;\n</code></pre>\n<p>This mode provides a good balance between features and binary size, and it is\nthe default behavior if no <code>--with-intl</code> flag is passed. The official binaries\nare also built in this mode.</p>\n",
"modules": [
{
"textRaw": "Providing ICU data at runtime",
"name": "providing_icu_data_at_runtime",
"desc": "<p>If the <code>small-icu</code> option is used, one can still provide additional locale data\nat runtime so that the JS methods would work for all ICU locales. Assuming the\ndata file is stored at <code>/some/directory</code>, it can be made available to ICU\nthrough either:</p>\n<ul>\n<li><p>The <a href=\"cli.html#cli_node_icu_data_file\"><code>NODE_ICU_DATA</code></a> environment variable:</p>\n<pre><code class=\"lang-shell\">env NODE_ICU_DATA=/some/directory node\n</code></pre>\n</li>\n<li><p>The <a href=\"cli.html#cli_icu_data_dir_file\"><code>--icu-data-dir</code></a> CLI parameter:</p>\n<pre><code class=\"lang-shell\">node --icu-data-dir=/some/directory\n</code></pre>\n</li>\n</ul>\n<p>(If both are specified, the <code>--icu-data-dir</code> CLI parameter takes precedence.)</p>\n<p>ICU is able to automatically find and load a variety of data formats, but the\ndata must be appropriate for the ICU version, and the file correctly named.\nThe most common name for the data file is <code>icudt5X[bl].dat</code>, where <code>5X</code> denotes\nthe intended ICU version, and <code>b</code> or <code>l</code> indicates the system&#39;s endianness.\nCheck <a href=\"http://userguide.icu-project.org/icudata\">&quot;ICU Data&quot;</a> article in the ICU User Guide for other supported formats\nand more details on ICU data in general.</p>\n<p>The <a href=\"https://www.npmjs.com/package/full-icu\">full-icu</a> npm module can greatly simplify ICU data installation by\ndetecting the ICU version of the running <code>node</code> executable and downloading the\nappropriate data file. After installing the module through <code>npm i full-icu</code>,\nthe data file will be available at <code>./node_modules/full-icu</code>. This path can be\nthen passed either to <code>NODE_ICU_DATA</code> or <code>--icu-data-dir</code> as shown above to\nenable full <code>Intl</code> support.</p>\n",
"type": "module",
"displayName": "Providing ICU data at runtime"
}
],
"type": "module",
"displayName": "Embed a limited set of ICU data (`small-icu`)"
},
{
"textRaw": "Embed the entire ICU (`full-icu`)",
"name": "embed_the_entire_icu_(`full-icu`)",
"desc": "<p>This option makes the resulting binary link against ICU statically and include\na full set of ICU data. A binary created this way has no further external\ndependencies and supports all locales, but might be rather large. See\n<a href=\"https://github.com/nodejs/node/blob/master/BUILDING.md#build-with-full-icu-support-all-locales-supported-by-icu\">BUILDING.md</a> on how to compile a binary using this mode.</p>\n",
"type": "module",
"displayName": "Embed the entire ICU (`full-icu`)"
}
],
"type": "misc",
"displayName": "Options for building Node.js"
},
{
"textRaw": "Detecting internationalization support",
"name": "detecting_internationalization_support",
"desc": "<p>To verify that ICU is enabled at all (<code>system-icu</code>, <code>small-icu</code>, or\n<code>full-icu</code>), simply checking the existence of <code>Intl</code> should suffice:</p>\n<pre><code class=\"lang-js\">const hasICU = typeof Intl === &#39;object&#39;;\n</code></pre>\n<p>Alternatively, checking for <code>process.versions.icu</code>, a property defined only\nwhen ICU is enabled, works too:</p>\n<pre><code class=\"lang-js\">const hasICU = typeof process.versions.icu === &#39;string&#39;;\n</code></pre>\n<p>To check for support for a non-English locale (i.e. <code>full-icu</code> or\n<code>system-icu</code>), <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat\"><code>Intl.DateTimeFormat</code></a> can be a good distinguishing factor:</p>\n<pre><code class=\"lang-js\">const hasFullICU = (() =&gt; {\n try {\n const january = new Date(9e8);\n const spanish = new Intl.DateTimeFormat(&#39;es&#39;, { month: &#39;long&#39; });\n return spanish.format(january) === &#39;enero&#39;;\n } catch (err) {\n return false;\n }\n})();\n</code></pre>\n<p>For more verbose tests for <code>Intl</code> support, the following resources may be found\nto be helpful:</p>\n<ul>\n<li><a href=\"https://github.com/srl295/btest402\">btest402</a>: Generally used to check whether Node.js with <code>Intl</code> support is\nbuilt correctly.</li>\n<li><a href=\"https://github.com/tc39/test262/tree/master/test/intl402\">Test262</a>: ECMAScript&#39;s official conformance test suite includes a section\ndedicated to ECMA-402.</li>\n</ul>\n",
"type": "misc",
"displayName": "Detecting internationalization support"
}
]
}
],
"modules": [
{
"textRaw": "Assert",
"name": "assert",
"introduced_in": "v0.1.21",
"stability": 2,
"stabilityText": "Stable",
"desc": "<p>The <code>assert</code> module provides a simple set of assertion tests that can be used to\ntest invariants.</p>\n<p>A <code>strict</code> and a <code>legacy</code> mode exist, while it is recommended to only use\n<a href=\"#assert_strict_mode\"><code>strict mode</code></a>.</p>\n<p>For more information about the used equality comparisons see\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness\">MDN&#39;s guide on equality comparisons and sameness</a>.</p>\n",
"classes": [
{
"textRaw": "Class: assert.AssertionError",
"type": "class",
"name": "assert.AssertionError",
"desc": "<p>A subclass of <code>Error</code> that indicates the failure of an assertion. All errors\nthrown by the <code>assert</code> module will be instances of the <code>AssertionError</code> class.</p>\n",
"signatures": [
{
"params": [
{
"textRaw": "`options` {Object} ",
"options": [
{
"textRaw": "`message` {string} If provided, the error message is going to be set to this value. ",
"name": "message",
"type": "string",
"desc": "If provided, the error message is going to be set to this value."
},
{
"textRaw": "`actual` {any} The `actual` property on the error instance is going to contain this value. Internally used for the `actual` error input in case e.g., [`assert.strictEqual()`] is used. ",
"name": "actual",
"type": "any",
"desc": "The `actual` property on the error instance is going to contain this value. Internally used for the `actual` error input in case e.g., [`assert.strictEqual()`] is used."
},
{
"textRaw": "`expected` {any} The `expected` property on the error instance is going to contain this value. Internally used for the `expected` error input in case e.g., [`assert.strictEqual()`] is used. ",
"name": "expected",
"type": "any",
"desc": "The `expected` property on the error instance is going to contain this value. Internally used for the `expected` error input in case e.g., [`assert.strictEqual()`] is used."
},
{
"textRaw": "`operator` {string} The `operator` property on the error instance is going to contain this value. Internally used to indicate what operation was used for comparison (or what assertion function triggered the error). ",
"name": "operator",
"type": "string",
"desc": "The `operator` property on the error instance is going to contain this value. Internally used to indicate what operation was used for comparison (or what assertion function triggered the error)."
},
{
"textRaw": "`stackStartFn` {Function} If provided, the generated stack trace is going to remove all frames up to the provided function. ",
"name": "stackStartFn",
"type": "Function",
"desc": "If provided, the generated stack trace is going to remove all frames up to the provided function."
}
],
"name": "options",
"type": "Object"
}
],
"desc": "<p>A subclass of <code>Error</code> that indicates the failure of an assertion.</p>\n<p>All instances contain the built-in <code>Error</code> properties (<code>message</code> and <code>name</code>)\nand:</p>\n<ul>\n<li><code>actual</code> {any} Set to the actual value in case e.g.,\n<a href=\"#assert_assert_strictequal_actual_expected_message\"><code>assert.strictEqual()</code></a> is used.</li>\n<li><code>expected</code> {any} Set to the expected value in case e.g.,\n<a href=\"#assert_assert_strictequal_actual_expected_message\"><code>assert.strictEqual()</code></a> is used.</li>\n<li><code>generatedMessage</code> {boolean} Indicates if the message was auto-generated\n(<code>true</code>) or not.</li>\n<li><code>code</code> {string} This is always set to the string <code>ERR_ASSERTION</code> to indicate\nthat the error is actually an assertion error.</li>\n<li><code>operator</code> {string} Set to the passed in operator value.</li>\n</ul>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;);\n\n// Generate an AssertionError to compare the error message later:\nconst { message } = new assert.AssertionError({\n actual: 1,\n expected: 2,\n operator: &#39;strictEqual&#39;\n});\n\n// Verify error output:\ntry {\n assert.strictEqual(1, 2);\n} catch (err) {\n assert(err instanceof assert.AssertionError);\n assert.strictEqual(err.message, message);\n assert.strictEqual(err.name, &#39;AssertionError [ERR_ASSERTION]&#39;);\n assert.strictEqual(err.actual, 1);\n assert.strictEqual(err.expected, 2);\n assert.strictEqual(err.code, &#39;ERR_ASSERTION&#39;);\n assert.strictEqual(err.operator, &#39;strictEqual&#39;);\n assert.strictEqual(err.generatedMessage, true);\n}\n</code></pre>\n"
},
{
"params": [
{
"name": "options"
}
],
"desc": "<p>A subclass of <code>Error</code> that indicates the failure of an assertion.</p>\n<p>All instances contain the built-in <code>Error</code> properties (<code>message</code> and <code>name</code>)\nand:</p>\n<ul>\n<li><code>actual</code> {any} Set to the actual value in case e.g.,\n<a href=\"#assert_assert_strictequal_actual_expected_message\"><code>assert.strictEqual()</code></a> is used.</li>\n<li><code>expected</code> {any} Set to the expected value in case e.g.,\n<a href=\"#assert_assert_strictequal_actual_expected_message\"><code>assert.strictEqual()</code></a> is used.</li>\n<li><code>generatedMessage</code> {boolean} Indicates if the message was auto-generated\n(<code>true</code>) or not.</li>\n<li><code>code</code> {string} This is always set to the string <code>ERR_ASSERTION</code> to indicate\nthat the error is actually an assertion error.</li>\n<li><code>operator</code> {string} Set to the passed in operator value.</li>\n</ul>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;);\n\n// Generate an AssertionError to compare the error message later:\nconst { message } = new assert.AssertionError({\n actual: 1,\n expected: 2,\n operator: &#39;strictEqual&#39;\n});\n\n// Verify error output:\ntry {\n assert.strictEqual(1, 2);\n} catch (err) {\n assert(err instanceof assert.AssertionError);\n assert.strictEqual(err.message, message);\n assert.strictEqual(err.name, &#39;AssertionError [ERR_ASSERTION]&#39;);\n assert.strictEqual(err.actual, 1);\n assert.strictEqual(err.expected, 2);\n assert.strictEqual(err.code, &#39;ERR_ASSERTION&#39;);\n assert.strictEqual(err.operator, &#39;strictEqual&#39;);\n assert.strictEqual(err.generatedMessage, true);\n}\n</code></pre>\n"
}
]
}
],
"modules": [
{
"textRaw": "Strict mode",
"name": "strict_mode",
"meta": {
"added": [
"v9.9.0"
],
"changes": [
{
"version": "v9.9.0",
"pr-url": "https://github.com/nodejs/node/pull/17615",
"description": "Added error diffs to the strict mode"
},
{
"version": "v9.9.0",
"pr-url": "https://github.com/nodejs/node/pull/17002",
"description": "Added strict mode to the assert module."
}
]
},
"desc": "<p>When using the <code>strict mode</code>, any <code>assert</code> function will use the equality used\nin the strict function mode. So <a href=\"#assert_assert_deepequal_actual_expected_message\"><code>assert.deepEqual()</code></a> will, for example,\nwork the same as <a href=\"#assert_assert_deepstrictequal_actual_expected_message\"><code>assert.deepStrictEqual()</code></a>.</p>\n<p>On top of that, error messages which involve objects produce an error diff\ninstead of displaying both objects. That is not the case for the legacy mode.</p>\n<p>It can be accessed using:</p>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;).strict;\n</code></pre>\n<p>Example error diff:</p>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;).strict;\n\nassert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, &#39;3&#39;]], 4, 5]);\n// AssertionError: Input A expected to strictly deep-equal input B:\n// + expected - actual ... Lines skipped\n//\n// [\n// [\n// ...\n// 2,\n// - 3\n// + &#39;3&#39;\n// ],\n// ...\n// 5\n// ]\n</code></pre>\n<p>To deactivate the colors, use the <code>NODE_DISABLE_COLORS</code> environment variable.\nPlease note that this will also deactivate the colors in the REPL.</p>\n",
"type": "module",
"displayName": "Strict mode"
},
{
"textRaw": "Legacy mode",
"name": "legacy_mode",
"stability": 0,
"stabilityText": "Deprecated: Use strict mode instead.",
"desc": "<p>When accessing <code>assert</code> directly instead of using the <code>strict</code> property, the\n<a href=\"https://tc39.github.io/ecma262/#sec-abstract-equality-comparison\">Abstract Equality Comparison</a> will be used for any function without &quot;strict&quot;\nin its name, such as <a href=\"#assert_assert_deepequal_actual_expected_message\"><code>assert.deepEqual()</code></a>.</p>\n<p>It can be accessed using:</p>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;);\n</code></pre>\n<p>It is recommended to use the <a href=\"#assert_strict_mode\"><code>strict mode</code></a> instead as the\n<a href=\"https://tc39.github.io/ecma262/#sec-abstract-equality-comparison\">Abstract Equality Comparison</a> can often have surprising results. This is\nespecially true for <a href=\"#assert_assert_deepequal_actual_expected_message\"><code>assert.deepEqual()</code></a>, where the comparison rules are\nlax:</p>\n<pre><code class=\"lang-js\">// WARNING: This does not throw an AssertionError!\nassert.deepEqual(/a/gi, new Date());\n</code></pre>\n",
"type": "module",
"displayName": "Legacy mode"
}
],
"methods": [
{
"textRaw": "assert(value[, message])",
"type": "method",
"name": "assert",
"meta": {
"added": [
"v0.5.9"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`value` {any} The input that is checked for being truthy. ",
"name": "value",
"type": "any",
"desc": "The input that is checked for being truthy."
},
{
"textRaw": "`message` {string|Error} ",
"name": "message",
"type": "string|Error",
"optional": true
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "message",
"optional": true
}
]
}
],
"desc": "<p>An alias of <a href=\"#assert_assert_ok_value_message\"><code>assert.ok()</code></a>.</p>\n"
},
{
"textRaw": "assert.deepEqual(actual, expected[, message])",
"type": "method",
"name": "deepEqual",
"meta": {
"added": [
"v0.1.21"
],
"changes": [
{
"version": "v9.0.0",
"pr-url": "https://github.com/nodejs/node/pull/15001",
"description": "The `Error` names and messages are now properly compared"
},
{
"version": "v8.0.0",
"pr-url": "https://github.com/nodejs/node/pull/12142",
"description": "The `Set` and `Map` content is also compared"
},
{
"version": "v6.4.0, v4.7.1",
"pr-url": "https://github.com/nodejs/node/pull/8002",
"description": "Typed array slices are handled correctly now."
},
{
"version": "v6.1.0, v4.5.0",
"pr-url": "https://github.com/nodejs/node/pull/6432",
"description": "Objects with circular references can be used as inputs now."
},
{
"version": "v5.10.1, v4.4.3",
"pr-url": "https://github.com/nodejs/node/pull/5910",
"description": "Handle non-`Uint8Array` typed arrays correctly."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`actual` {any} ",
"name": "actual",
"type": "any"
},
{
"textRaw": "`expected` {any} ",
"name": "expected",
"type": "any"
},
{
"textRaw": "`message` {string|Error} ",
"name": "message",
"type": "string|Error",
"optional": true
}
]
},
{
"params": [
{
"name": "actual"
},
{
"name": "expected"
},
{
"name": "message",
"optional": true
}
]
}
],
"desc": "<p><strong>Strict mode</strong></p>\n<p>An alias of <a href=\"#assert_assert_deepstrictequal_actual_expected_message\"><code>assert.deepStrictEqual()</code></a>.</p>\n<p><strong>Legacy mode</strong></p>\n<blockquote>\n<p>Stability: 0 - Deprecated: Use <a href=\"#assert_assert_deepstrictequal_actual_expected_message\"><code>assert.deepStrictEqual()</code></a> instead.</p>\n</blockquote>\n<p>Tests for deep equality between the <code>actual</code> and <code>expected</code> parameters.\nPrimitive values are compared with the <a href=\"https://tc39.github.io/ecma262/#sec-abstract-equality-comparison\">Abstract Equality Comparison</a>\n( <code>==</code> ).</p>\n<p>Only <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties\">enumerable &quot;own&quot; properties</a> are considered. The\n<a href=\"#assert_assert_deepequal_actual_expected_message\"><code>assert.deepEqual()</code></a> implementation does not test the\n<a href=\"https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots\"><code>[[Prototype]]</code></a> of objects or enumerable own <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol\"><code>Symbol</code></a>\nproperties. For such checks, consider using <a href=\"#assert_assert_deepstrictequal_actual_expected_message\"><code>assert.deepStrictEqual()</code></a>\ninstead. <a href=\"#assert_assert_deepequal_actual_expected_message\"><code>assert.deepEqual()</code></a> can have potentially surprising results. The\nfollowing example does not throw an <code>AssertionError</code> because the properties on\nthe <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\"><code>RegExp</code></a> object are not enumerable:</p>\n<pre><code class=\"lang-js\">// WARNING: This does not throw an AssertionError!\nassert.deepEqual(/a/gi, new Date());\n</code></pre>\n<p>An exception is made for <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map\"><code>Map</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set\"><code>Set</code></a>. <code>Map</code>s and <code>Set</code>s have their\ncontained items compared too, as expected.</p>\n<p>&quot;Deep&quot; equality means that the enumerable &quot;own&quot; properties of child objects\nare evaluated also:</p>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;);\n\nconst obj1 = {\n a: {\n b: 1\n }\n};\nconst obj2 = {\n a: {\n b: 2\n }\n};\nconst obj3 = {\n a: {\n b: 1\n }\n};\nconst obj4 = Object.create(obj1);\n\nassert.deepEqual(obj1, obj1);\n// OK\n\n// Values of b are different:\nassert.deepEqual(obj1, obj2);\n// AssertionError: { a: { b: 1 } } deepEqual { a: { b: 2 } }\n\nassert.deepEqual(obj1, obj3);\n// OK\n\n// Prototypes are ignored:\nassert.deepEqual(obj1, obj4);\n// AssertionError: { a: { b: 1 } } deepEqual {}\n</code></pre>\n<p>If the values are not equal, an <code>AssertionError</code> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is undefined, a default error message is assigned. If the <code>message</code>\nparameter is an instance of an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> then it will be thrown instead of the\n<code>AssertionError</code>.</p>\n"
},
{
"textRaw": "assert.deepStrictEqual(actual, expected[, message])",
"type": "method",
"name": "deepStrictEqual",
"meta": {
"added": [
"v1.2.0"
],
"changes": [
{
"version": "v9.0.0",
"pr-url": "https://github.com/nodejs/node/pull/15169",
"description": "Enumerable symbol properties are now compared."
},
{
"version": "v9.0.0",
"pr-url": "https://github.com/nodejs/node/pull/15036",
"description": "The `NaN` is now compared using the [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero) comparison."
},
{
"version": "v8.5.0",
"pr-url": "https://github.com/nodejs/node/pull/15001",
"description": "The `Error` names and messages are now properly compared"
},
{
"version": "v8.0.0",
"pr-url": "https://github.com/nodejs/node/pull/12142",
"description": "The `Set` and `Map` content is also compared"
},
{
"version": "v6.4.0, v4.7.1",
"pr-url": "https://github.com/nodejs/node/pull/8002",
"description": "Typed array slices are handled correctly now."
},
{
"version": "v6.1.0",
"pr-url": "https://github.com/nodejs/node/pull/6432",
"description": "Objects with circular references can be used as inputs now."
},
{
"version": "v5.10.1, v4.4.3",
"pr-url": "https://github.com/nodejs/node/pull/5910",
"description": "Handle non-`Uint8Array` typed arrays correctly."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`actual` {any} ",
"name": "actual",
"type": "any"
},
{
"textRaw": "`expected` {any} ",
"name": "expected",
"type": "any"
},
{
"textRaw": "`message` {string|Error} ",
"name": "message",
"type": "string|Error",
"optional": true
}
]
},
{
"params": [
{
"name": "actual"
},
{
"name": "expected"
},
{
"name": "message",
"optional": true
}
]
}
],
"desc": "<p>Tests for deep equality between the <code>actual</code> and <code>expected</code> parameters.\n&quot;Deep&quot; equality means that the enumerable &quot;own&quot; properties of child objects\nare recursively evaluated also by the following rules.</p>\n",
"modules": [
{
"textRaw": "Comparison details",
"name": "comparison_details",
"desc": "<ul>\n<li>Primitive values are compared using the <a href=\"https://tc39.github.io/ecma262/#sec-samevalue\">SameValue Comparison</a>, used by\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\"><code>Object.is()</code></a>.</li>\n<li><a href=\"https://tc39.github.io/ecma262/#sec-object.prototype.tostring\">Type tags</a> of objects should be the same.</li>\n<li><a href=\"https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots\"><code>[[Prototype]]</code></a> of objects are compared using\nthe <a href=\"https://tc39.github.io/ecma262/#sec-strict-equality-comparison\">Strict Equality Comparison</a>.</li>\n<li>Only <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties\">enumerable &quot;own&quot; properties</a> are considered.</li>\n<li><a href=\"errors.html#errors_class_error\"><code>Error</code></a> names and messages are always compared, even if these are not\nenumerable properties.</li>\n<li>Enumerable own <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol\"><code>Symbol</code></a> properties are compared as well.</li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Primitive#Primitive_wrapper_objects_in_JavaScript\">Object wrappers</a> are compared both as objects and unwrapped values.</li>\n<li><code>Object</code> properties are compared unordered.</li>\n<li><code>Map</code> keys and <code>Set</code> items are compared unordered.</li>\n<li>Recursion stops when both sides differ or both sides encounter a circular\nreference.</li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap\"><code>WeakMap</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet\"><code>WeakSet</code></a> comparison does not rely on their values. See\nbelow for further details.</li>\n</ul>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;).strict;\n\n// This fails because 1 !== &#39;1&#39;.\nassert.deepStrictEqual({ a: 1 }, { a: &#39;1&#39; });\n// AssertionError: Input A expected to strictly deep-equal input B:\n// + expected - actual\n// {\n// - a: 1\n// + a: &#39;1&#39;\n// }\n\n// The following objects don&#39;t have own properties\nconst date = new Date();\nconst object = {};\nconst fakeDate = {};\nObject.setPrototypeOf(fakeDate, Date.prototype);\n\n// Different [[Prototype]]:\nassert.deepStrictEqual(object, fakeDate);\n// AssertionError: Input A expected to strictly deep-equal input B:\n// + expected - actual\n// - {}\n// + Date {}\n\n// Different type tags:\nassert.deepStrictEqual(date, fakeDate);\n// AssertionError: Input A expected to strictly deep-equal input B:\n// + expected - actual\n// - 2018-04-26T00:49:08.604Z\n// + Date {}\n\nassert.deepStrictEqual(NaN, NaN);\n// OK, because of the SameValue comparison\n\n// Different unwrapped numbers:\nassert.deepStrictEqual(new Number(1), new Number(2));\n// AssertionError: Input A expected to strictly deep-equal input B:\n// + expected - actual\n// - [Number: 1]\n// + [Number: 2]\n\nassert.deepStrictEqual(new String(&#39;foo&#39;), Object(&#39;foo&#39;));\n// OK because the object and the string are identical when unwrapped.\n\nassert.deepStrictEqual(-0, -0);\n// OK\n\n// Different zeros using the SameValue Comparison:\nassert.deepStrictEqual(0, -0);\n// AssertionError: Input A expected to strictly deep-equal input B:\n// + expected - actual\n// - 0\n// + -0\n\nconst symbol1 = Symbol();\nconst symbol2 = Symbol();\nassert.deepStrictEqual({ [symbol1]: 1 }, { [symbol1]: 1 });\n// OK, because it is the same symbol on both objects.\nassert.deepStrictEqual({ [symbol1]: 1 }, { [symbol2]: 1 });\n// AssertionError [ERR_ASSERTION]: Input objects not identical:\n// {\n// [Symbol()]: 1\n// }\n\nconst weakMap1 = new WeakMap();\nconst weakMap2 = new WeakMap([[{}, {}]]);\nconst weakMap3 = new WeakMap();\nweakMap3.unequal = true;\n\nassert.deepStrictEqual(weakMap1, weakMap2);\n// OK, because it is impossible to compare the entries\n\n// Fails because weakMap3 has a property that weakMap1 does not contain:\nassert.deepStrictEqual(weakMap1, weakMap3);\n// AssertionError: Input A expected to strictly deep-equal input B:\n// + expected - actual\n// WeakMap {\n// - [items unknown]\n// + [items unknown],\n// + unequal: true\n// }\n</code></pre>\n<p>If the values are not equal, an <code>AssertionError</code> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is undefined, a default error message is assigned. If the <code>message</code>\nparameter is an instance of an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> then it will be thrown instead of the\n<code>AssertionError</code>.</p>\n",
"type": "module",
"displayName": "Comparison details"
}
]
},
{
"textRaw": "assert.doesNotReject(block[, error][, message])",
"type": "method",
"name": "doesNotReject",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`block` {Function|Promise} ",
"name": "block",
"type": "Function|Promise"
},
{
"textRaw": "`error` {RegExp|Function} ",
"name": "error",
"type": "RegExp|Function",
"optional": true
},
{
"textRaw": "`message` {string|Error} ",
"name": "message",
"type": "string|Error",
"optional": true
}
]
},
{
"params": [
{
"name": "block"
},
{
"name": "error",
"optional": true
},
{
"name": "message",
"optional": true
}
]
}
],
"desc": "<p>Awaits the <code>block</code> promise or, if <code>block</code> is a function, immediately calls the\nfunction and awaits the returned promise to complete. It will then check that\nthe promise is not rejected.</p>\n<p>If <code>block</code> is a function and it throws an error synchronously,\n<code>assert.doesNotReject()</code> will return a rejected <code>Promise</code> with that error. If\nthe function does not return a promise, <code>assert.doesNotReject()</code> will return a\nrejected <code>Promise</code> with an <a href=\"errors.html#errors_err_invalid_return_value\"><code>ERR_INVALID_RETURN_VALUE</code></a> error. In both cases\nthe error handler is skipped.</p>\n<p>Please note: Using <code>assert.doesNotReject()</code> is actually not useful because there\nis little benefit by catching a rejection and then rejecting it again. Instead,\nconsider adding a comment next to the specific code path that should not reject\nand keep error messages as expressive as possible.</p>\n<p>If specified, <code>error</code> can be a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes\"><code>Class</code></a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\"><code>RegExp</code></a> or a validation\nfunction. See <a href=\"#assert_assert_throws_block_error_message\"><code>assert.throws()</code></a> for more details.</p>\n<p>Besides the async nature to await the completion behaves identically to\n<a href=\"#assert_assert_doesnotthrow_block_error_message\"><code>assert.doesNotThrow()</code></a>.</p>\n<pre><code class=\"lang-js\">(async () =&gt; {\n await assert.doesNotReject(\n async () =&gt; {\n throw new TypeError(&#39;Wrong value&#39;);\n },\n SyntaxError\n );\n})();\n</code></pre>\n<pre><code class=\"lang-js\">assert.doesNotReject(Promise.reject(new TypeError(&#39;Wrong value&#39;)))\n .then(() =&gt; {\n // ...\n });\n</code></pre>\n"
},
{
"textRaw": "assert.doesNotThrow(block[, error][, message])",
"type": "method",
"name": "doesNotThrow",
"meta": {
"added": [
"v0.1.21"
],
"changes": [
{
"version": "v5.11.0, v4.4.5",
"pr-url": "https://github.com/nodejs/node/pull/2407",
"description": "The `message` parameter is respected now."
},
{
"version": "v4.2.0",
"pr-url": "https://github.com/nodejs/node/pull/3276",
"description": "The `error` parameter can now be an arrow function."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`block` {Function} ",
"name": "block",
"type": "Function"
},
{
"textRaw": "`error` {RegExp|Function} ",
"name": "error",
"type": "RegExp|Function",
"optional": true
},
{
"textRaw": "`message` {string|Error} ",
"name": "message",
"type": "string|Error",
"optional": true
}
]
},
{
"params": [
{
"name": "block"
},
{
"name": "error",
"optional": true
},
{
"name": "message",
"optional": true
}
]
}
],
"desc": "<p>Asserts that the function <code>block</code> does not throw an error.</p>\n<p>Please note: Using <code>assert.doesNotThrow()</code> is actually not useful because there\nis no benefit by catching an error and then rethrowing it. Instead, consider\nadding a comment next to the specific code path that should not throw and keep\nerror messages as expressive as possible.</p>\n<p>When <code>assert.doesNotThrow()</code> is called, it will immediately call the <code>block</code>\nfunction.</p>\n<p>If an error is thrown and it is the same type as that specified by the <code>error</code>\nparameter, then an <code>AssertionError</code> is thrown. If the error is of a different\ntype, or if the <code>error</code> parameter is undefined, the error is propagated back\nto the caller.</p>\n<p>If specified, <code>error</code> can be a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes\"><code>Class</code></a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\"><code>RegExp</code></a> or a validation\nfunction. See <a href=\"#assert_assert_throws_block_error_message\"><code>assert.throws()</code></a> for more details.</p>\n<p>The following, for instance, will throw the <a href=\"errors.html#errors_class_typeerror\"><code>TypeError</code></a> because there is no\nmatching error type in the assertion:</p>\n<!-- eslint-disable no-restricted-syntax -->\n<pre><code class=\"lang-js\">assert.doesNotThrow(\n () =&gt; {\n throw new TypeError(&#39;Wrong value&#39;);\n },\n SyntaxError\n);\n</code></pre>\n<p>However, the following will result in an <code>AssertionError</code> with the message\n&#39;Got unwanted exception...&#39;:</p>\n<!-- eslint-disable no-restricted-syntax -->\n<pre><code class=\"lang-js\">assert.doesNotThrow(\n () =&gt; {\n throw new TypeError(&#39;Wrong value&#39;);\n },\n TypeError\n);\n</code></pre>\n<p>If an <code>AssertionError</code> is thrown and a value is provided for the <code>message</code>\nparameter, the value of <code>message</code> will be appended to the <code>AssertionError</code>\nmessage:</p>\n<!-- eslint-disable no-restricted-syntax -->\n<pre><code class=\"lang-js\">assert.doesNotThrow(\n () =&gt; {\n throw new TypeError(&#39;Wrong value&#39;);\n },\n /Wrong value/,\n &#39;Whoops&#39;\n);\n// Throws: AssertionError: Got unwanted exception: Whoops\n</code></pre>\n"
},
{
"textRaw": "assert.equal(actual, expected[, message])",
"type": "method",
"name": "equal",
"meta": {
"added": [
"v0.1.21"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`actual` {any} ",
"name": "actual",
"type": "any"
},
{
"textRaw": "`expected` {any} ",
"name": "expected",
"type": "any"
},
{
"textRaw": "`message` {string|Error} ",
"name": "message",
"type": "string|Error",
"optional": true
}
]
},
{
"params": [
{
"name": "actual"
},
{
"name": "expected"
},
{
"name": "message",
"optional": true
}
]
}
],
"desc": "<p><strong>Strict mode</strong></p>\n<p>An alias of <a href=\"#assert_assert_strictequal_actual_expected_message\"><code>assert.strictEqual()</code></a>.</p>\n<p><strong>Legacy mode</strong></p>\n<blockquote>\n<p>Stability: 0 - Deprecated: Use <a href=\"#assert_assert_strictequal_actual_expected_message\"><code>assert.strictEqual()</code></a> instead.</p>\n</blockquote>\n<p>Tests shallow, coercive equality between the <code>actual</code> and <code>expected</code> parameters\nusing the <a href=\"https://tc39.github.io/ecma262/#sec-abstract-equality-comparison\">Abstract Equality Comparison</a> ( <code>==</code> ).</p>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;);\n\nassert.equal(1, 1);\n// OK, 1 == 1\nassert.equal(1, &#39;1&#39;);\n// OK, 1 == &#39;1&#39;\n\nassert.equal(1, 2);\n// AssertionError: 1 == 2\nassert.equal({ a: { b: 1 } }, { a: { b: 1 } });\n// AssertionError: { a: { b: 1 } } == { a: { b: 1 } }\n</code></pre>\n<p>If the values are not equal, an <code>AssertionError</code> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is undefined, a default error message is assigned. If the <code>message</code>\nparameter is an instance of an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> then it will be thrown instead of the\n<code>AssertionError</code>.</p>\n"
},
{
"textRaw": "assert.fail([message])",
"type": "method",
"name": "fail",
"meta": {
"added": [
"v0.1.21"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`message` {string|Error} **Default:** `'Failed'` ",
"name": "message",
"type": "string|Error",
"default": "`'Failed'`",
"optional": true
}
]
},
{
"params": [
{
"name": "message",
"optional": true
}
]
}
],
"desc": "<p>Throws an <code>AssertionError</code> with the provided error message or a default error\nmessage. If the <code>message</code> parameter is an instance of an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> then it\nwill be thrown instead of the <code>AssertionError</code>.</p>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;).strict;\n\nassert.fail();\n// AssertionError [ERR_ASSERTION]: Failed\n\nassert.fail(&#39;boom&#39;);\n// AssertionError [ERR_ASSERTION]: boom\n\nassert.fail(new TypeError(&#39;need array&#39;));\n// TypeError: need array\n</code></pre>\n<p>Using <code>assert.fail()</code> with more than two arguments is possible but deprecated.\nSee below for further details.</p>\n"
},
{
"textRaw": "assert.fail(actual, expected[, message[, operator[, stackStartFunction]]])",
"type": "method",
"name": "fail",
"meta": {
"added": [
"v0.1.21"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18418",
"description": "Calling `assert.fail()` with more than one argument is deprecated and emits a warning."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`actual` {any} ",
"name": "actual",
"type": "any"
},
{
"textRaw": "`expected` {any} ",
"name": "expected",
"type": "any"
},
{
"textRaw": "`message` {string|Error} ",
"name": "message",
"type": "string|Error",
"optional": true
},
{
"textRaw": "`operator` {string} **Default:** `'!='` ",
"name": "operator",
"type": "string",
"default": "`'!='`",
"optional": true
},
{
"textRaw": "`stackStartFunction` {Function} **Default:** `assert.fail` ",
"name": "stackStartFunction",
"type": "Function",
"default": "`assert.fail`",
"optional": true
}
]
},
{
"params": [
{
"name": "actual"
},
{
"name": "expected"
},
{
"name": "message",
"optional": true
},
{
"name": "operator",
"optional": true
},
{
"name": "stackStartFunction",
"optional": true
}
]
}
],
"desc": "<p>Stability: 0 - Deprecated: Use <code>assert.fail([message])</code> or other assert\nfunctions instead.</p>\n<p>If <code>message</code> is falsy, the error message is set as the values of <code>actual</code> and\n<code>expected</code> separated by the provided <code>operator</code>. If just the two <code>actual</code> and\n<code>expected</code> arguments are provided, <code>operator</code> will default to <code>&#39;!=&#39;</code>. If\n<code>message</code> is provided as third argument it will be used as the error message and\nthe other arguments will be stored as properties on the thrown object. If\n<code>stackStartFunction</code> is provided, all stack frames above that function will be\nremoved from stacktrace (see <a href=\"errors.html#errors_error_capturestacktrace_targetobject_constructoropt\"><code>Error.captureStackTrace</code></a>). If no arguments are\ngiven, the default message <code>Failed</code> will be used.</p>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;).strict;\n\nassert.fail(&#39;a&#39;, &#39;b&#39;);\n// AssertionError [ERR_ASSERTION]: &#39;a&#39; != &#39;b&#39;\n\nassert.fail(1, 2, undefined, &#39;&gt;&#39;);\n// AssertionError [ERR_ASSERTION]: 1 &gt; 2\n\nassert.fail(1, 2, &#39;fail&#39;);\n// AssertionError [ERR_ASSERTION]: fail\n\nassert.fail(1, 2, &#39;whoops&#39;, &#39;&gt;&#39;);\n// AssertionError [ERR_ASSERTION]: whoops\n\nassert.fail(1, 2, new TypeError(&#39;need array&#39;));\n// TypeError: need array\n</code></pre>\n<p>In the last three cases <code>actual</code>, <code>expected</code>, and <code>operator</code> have no\ninfluence on the error message.</p>\n<p>Example use of <code>stackStartFunction</code> for truncating the exception&#39;s stacktrace:</p>\n<pre><code class=\"lang-js\">function suppressFrame() {\n assert.fail(&#39;a&#39;, &#39;b&#39;, undefined, &#39;!==&#39;, suppressFrame);\n}\nsuppressFrame();\n// AssertionError [ERR_ASSERTION]: &#39;a&#39; !== &#39;b&#39;\n// at repl:1:1\n// at ContextifyScript.Script.runInThisContext (vm.js:44:33)\n// ...\n</code></pre>\n"
},
{
"textRaw": "assert.ifError(value)",
"type": "method",
"name": "ifError",
"meta": {
"added": [
"v0.1.97"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18247",
"description": "Instead of throwing the original error it is now wrapped into an `AssertionError` that contains the full stack trace."
},
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18247",
"description": "Value may now only be `undefined` or `null`. Before all falsy values were handled the same as `null` and did not throw."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`value` {any} ",
"name": "value",
"type": "any"
}
]
},
{
"params": [
{
"name": "value"
}
]
}
],
"desc": "<p>Throws <code>value</code> if <code>value</code> is not <code>undefined</code> or <code>null</code>. This is useful when\ntesting the <code>error</code> argument in callbacks. The stack trace contains all frames\nfrom the error passed to <code>ifError()</code> including the potential new frames for\n<code>ifError()</code> itself. See below for an example.</p>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;).strict;\n\nassert.ifError(null);\n// OK\nassert.ifError(0);\n// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 0\nassert.ifError(&#39;error&#39;);\n// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: &#39;error&#39;\nassert.ifError(new Error());\n// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Error\n\n// Create some random error frames.\nlet err;\n(function errorFrame() {\n err = new Error(&#39;test error&#39;);\n})();\n\n(function ifErrorFrame() {\n assert.ifError(err);\n})();\n// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error\n// at ifErrorFrame\n// at errorFrame\n</code></pre>\n"
},
{
"textRaw": "assert.notDeepEqual(actual, expected[, message])",
"type": "method",
"name": "notDeepEqual",
"meta": {
"added": [
"v0.1.21"
],
"changes": [
{
"version": "v9.0.0",
"pr-url": "https://github.com/nodejs/node/pull/15001",
"description": "The `Error` names and messages are now properly compared"
},
{
"version": "v8.0.0",
"pr-url": "https://github.com/nodejs/node/pull/12142",
"description": "The `Set` and `Map` content is also compared"
},
{
"version": "v6.4.0, v4.7.1",
"pr-url": "https://github.com/nodejs/node/pull/8002",
"description": "Typed array slices are handled correctly now."
},
{
"version": "v6.1.0, v4.5.0",
"pr-url": "https://github.com/nodejs/node/pull/6432",
"description": "Objects with circular references can be used as inputs now."
},
{
"version": "v5.10.1, v4.4.3",
"pr-url": "https://github.com/nodejs/node/pull/5910",
"description": "Handle non-`Uint8Array` typed arrays correctly."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`actual` {any} ",
"name": "actual",
"type": "any"
},
{
"textRaw": "`expected` {any} ",
"name": "expected",
"type": "any"
},
{
"textRaw": "`message` {string|Error} ",
"name": "message",
"type": "string|Error",
"optional": true
}
]
},
{
"params": [
{
"name": "actual"
},
{
"name": "expected"
},
{
"name": "message",
"optional": true
}
]
}
],
"desc": "<p><strong>Strict mode</strong></p>\n<p>An alias of <a href=\"#assert_assert_notdeepstrictequal_actual_expected_message\"><code>assert.notDeepStrictEqual()</code></a>.</p>\n<p><strong>Legacy mode</strong></p>\n<blockquote>\n<p>Stability: 0 - Deprecated: Use <a href=\"#assert_assert_notdeepstrictequal_actual_expected_message\"><code>assert.notDeepStrictEqual()</code></a> instead.</p>\n</blockquote>\n<p>Tests for any deep inequality. Opposite of <a href=\"#assert_assert_deepequal_actual_expected_message\"><code>assert.deepEqual()</code></a>.</p>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;);\n\nconst obj1 = {\n a: {\n b: 1\n }\n};\nconst obj2 = {\n a: {\n b: 2\n }\n};\nconst obj3 = {\n a: {\n b: 1\n }\n};\nconst obj4 = Object.create(obj1);\n\nassert.notDeepEqual(obj1, obj1);\n// AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }\n\nassert.notDeepEqual(obj1, obj2);\n// OK\n\nassert.notDeepEqual(obj1, obj3);\n// AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }\n\nassert.notDeepEqual(obj1, obj4);\n// OK\n</code></pre>\n<p>If the values are deeply equal, an <code>AssertionError</code> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is undefined, a default error message is assigned. If the <code>message</code>\nparameter is an instance of an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> then it will be thrown instead of the\n<code>AssertionError</code>.</p>\n"
},
{
"textRaw": "assert.notDeepStrictEqual(actual, expected[, message])",
"type": "method",
"name": "notDeepStrictEqual",
"meta": {
"added": [
"v1.2.0"
],
"changes": [
{
"version": "v9.0.0",
"pr-url": "https://github.com/nodejs/node/pull/15398",
"description": "The `-0` and `+0` are not considered equal anymore."
},
{
"version": "v9.0.0",
"pr-url": "https://github.com/nodejs/node/pull/15036",
"description": "The `NaN` is now compared using the [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero) comparison."
},
{
"version": "v9.0.0",
"pr-url": "https://github.com/nodejs/node/pull/15001",
"description": "The `Error` names and messages are now properly compared"
},
{
"version": "v8.0.0",
"pr-url": "https://github.com/nodejs/node/pull/12142",
"description": "The `Set` and `Map` content is also compared"
},
{
"version": "v6.4.0, v4.7.1",
"pr-url": "https://github.com/nodejs/node/pull/8002",
"description": "Typed array slices are handled correctly now."
},
{
"version": "v6.1.0",
"pr-url": "https://github.com/nodejs/node/pull/6432",
"description": "Objects with circular references can be used as inputs now."
},
{
"version": "v5.10.1, v4.4.3",
"pr-url": "https://github.com/nodejs/node/pull/5910",
"description": "Handle non-`Uint8Array` typed arrays correctly."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`actual` {any} ",
"name": "actual",
"type": "any"
},
{
"textRaw": "`expected` {any} ",
"name": "expected",
"type": "any"
},
{
"textRaw": "`message` {string|Error} ",
"name": "message",
"type": "string|Error",
"optional": true
}
]
},
{
"params": [
{
"name": "actual"
},
{
"name": "expected"
},
{
"name": "message",
"optional": true
}
]
}
],
"desc": "<p>Tests for deep strict inequality. Opposite of <a href=\"#assert_assert_deepstrictequal_actual_expected_message\"><code>assert.deepStrictEqual()</code></a>.</p>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;).strict;\n\nassert.notDeepStrictEqual({ a: 1 }, { a: &#39;1&#39; });\n// OK\n</code></pre>\n<p>If the values are deeply and strictly equal, an <code>AssertionError</code> is thrown with\na <code>message</code> property set equal to the value of the <code>message</code> parameter. If the\n<code>message</code> parameter is undefined, a default error message is assigned. If the\n<code>message</code> parameter is an instance of an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> then it will be thrown\ninstead of the <code>AssertionError</code>.</p>\n"
},
{
"textRaw": "assert.notEqual(actual, expected[, message])",
"type": "method",
"name": "notEqual",
"meta": {
"added": [
"v0.1.21"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`actual` {any} ",
"name": "actual",
"type": "any"
},
{
"textRaw": "`expected` {any} ",
"name": "expected",
"type": "any"
},
{
"textRaw": "`message` {string|Error} ",
"name": "message",
"type": "string|Error",
"optional": true
}
]
},
{
"params": [
{
"name": "actual"
},
{
"name": "expected"
},
{
"name": "message",
"optional": true
}
]
}
],
"desc": "<p><strong>Strict mode</strong></p>\n<p>An alias of <a href=\"#assert_assert_notstrictequal_actual_expected_message\"><code>assert.notStrictEqual()</code></a>.</p>\n<p><strong>Legacy mode</strong></p>\n<blockquote>\n<p>Stability: 0 - Deprecated: Use <a href=\"#assert_assert_notstrictequal_actual_expected_message\"><code>assert.notStrictEqual()</code></a> instead.</p>\n</blockquote>\n<p>Tests shallow, coercive inequality with the <a href=\"https://tc39.github.io/ecma262/#sec-abstract-equality-comparison\">Abstract Equality Comparison</a>\n( <code>!=</code> ).</p>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;);\n\nassert.notEqual(1, 2);\n// OK\n\nassert.notEqual(1, 1);\n// AssertionError: 1 != 1\n\nassert.notEqual(1, &#39;1&#39;);\n// AssertionError: 1 != &#39;1&#39;\n</code></pre>\n<p>If the values are equal, an <code>AssertionError</code> is thrown with a <code>message</code> property\nset equal to the value of the <code>message</code> parameter. If the <code>message</code> parameter is\nundefined, a default error message is assigned. If the <code>message</code> parameter is an\ninstance of an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> then it will be thrown instead of the\n<code>AssertionError</code>.</p>\n"
},
{
"textRaw": "assert.notStrictEqual(actual, expected[, message])",
"type": "method",
"name": "notStrictEqual",
"meta": {
"added": [
"v0.1.21"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/17003",
"description": "Used comparison changed from Strict Equality to `Object.is()`"
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`actual` {any} ",
"name": "actual",
"type": "any"
},
{
"textRaw": "`expected` {any} ",
"name": "expected",
"type": "any"
},
{
"textRaw": "`message` {string|Error} ",
"name": "message",
"type": "string|Error",
"optional": true
}
]
},
{
"params": [
{
"name": "actual"
},
{
"name": "expected"
},
{
"name": "message",
"optional": true
}
]
}
],
"desc": "<p>Tests strict inequality between the <code>actual</code> and <code>expected</code> parameters as\ndetermined by the <a href=\"https://tc39.github.io/ecma262/#sec-samevalue\">SameValue Comparison</a>.</p>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;).strict;\n\nassert.notStrictEqual(1, 2);\n// OK\n\nassert.notStrictEqual(1, 1);\n// AssertionError [ERR_ASSERTION]: Identical input passed to notStrictEqual: 1\n\nassert.notStrictEqual(1, &#39;1&#39;);\n// OK\n</code></pre>\n<p>If the values are strictly equal, an <code>AssertionError</code> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is undefined, a default error message is assigned. If the <code>message</code>\nparameter is an instance of an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> then it will be thrown instead of the\n<code>AssertionError</code>.</p>\n"
},
{
"textRaw": "assert.ok(value[, message])",
"type": "method",
"name": "ok",
"meta": {
"added": [
"v0.1.21"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18319",
"description": "The `assert.ok()` (no arguments) will now use a predefined error message."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`value` {any} ",
"name": "value",
"type": "any"
},
{
"textRaw": "`message` {string|Error} ",
"name": "message",
"type": "string|Error",
"optional": true
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "message",
"optional": true
}
]
}
],
"desc": "<p>Tests if <code>value</code> is truthy. It is equivalent to\n<code>assert.equal(!!value, true, message)</code>.</p>\n<p>If <code>value</code> is not truthy, an <code>AssertionError</code> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is <code>undefined</code>, a default error message is assigned. If the <code>message</code>\nparameter is an instance of an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> then it will be thrown instead of the\n<code>AssertionError</code>.\nIf no arguments are passed in at all <code>message</code> will be set to the string:\n<code>&#39;No value argument passed to `assert.ok()`&#39;</code>.</p>\n<p>Be aware that in the <code>repl</code> the error message will be different to the one\nthrown in a file! See below for further details.</p>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;).strict;\n\nassert.ok(true);\n// OK\nassert.ok(1);\n// OK\n\nassert.ok();\n// AssertionError: No value argument passed to `assert.ok()`\n\nassert.ok(false, &#39;it\\&#39;s false&#39;);\n// AssertionError: it&#39;s false\n\n// In the repl:\nassert.ok(typeof 123 === &#39;string&#39;);\n// AssertionError: false == true\n\n// In a file (e.g. test.js):\nassert.ok(typeof 123 === &#39;string&#39;);\n// AssertionError: The expression evaluated to a falsy value:\n//\n// assert.ok(typeof 123 === &#39;string&#39;)\n\nassert.ok(false);\n// AssertionError: The expression evaluated to a falsy value:\n//\n// assert.ok(false)\n\nassert.ok(0);\n// AssertionError: The expression evaluated to a falsy value:\n//\n// assert.ok(0)\n\n// Using `assert()` works the same:\nassert(0);\n// AssertionError: The expression evaluated to a falsy value:\n//\n// assert(0)\n</code></pre>\n"
},
{
"textRaw": "assert.rejects(block[, error][, message])",
"type": "method",
"name": "rejects",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`block` {Function|Promise} ",
"name": "block",
"type": "Function|Promise"
},
{
"textRaw": "`error` {RegExp|Function|Object|Error} ",
"name": "error",
"type": "RegExp|Function|Object|Error",
"optional": true
},
{
"textRaw": "`message` {string|Error} ",
"name": "message",
"type": "string|Error",
"optional": true
}
]
},
{
"params": [
{
"name": "block"
},
{
"name": "error",
"optional": true
},
{
"name": "message",
"optional": true
}
]
}
],
"desc": "<p>Awaits the <code>block</code> promise or, if <code>block</code> is a function, immediately calls the\nfunction and awaits the returned promise to complete. It will then check that\nthe promise is rejected.</p>\n<p>If <code>block</code> is a function and it throws an error synchronously,\n<code>assert.rejects()</code> will return a rejected <code>Promise</code> with that error. If the\nfunction does not return a promise, <code>assert.rejects()</code> will return a rejected\n<code>Promise</code> with an <a href=\"errors.html#errors_err_invalid_return_value\"><code>ERR_INVALID_RETURN_VALUE</code></a> error. In both cases the error\nhandler is skipped.</p>\n<p>Besides the async nature to await the completion behaves identically to\n<a href=\"#assert_assert_throws_block_error_message\"><code>assert.throws()</code></a>.</p>\n<p>If specified, <code>error</code> can be a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes\"><code>Class</code></a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\"><code>RegExp</code></a>, a validation function,\nan object where each property will be tested for, or an instance of error where\neach property will be tested for including the non-enumerable <code>message</code> and\n<code>name</code> properties.</p>\n<p>If specified, <code>message</code> will be the message provided by the <code>AssertionError</code> if\nthe block fails to reject.</p>\n<pre><code class=\"lang-js\">(async () =&gt; {\n await assert.rejects(\n async () =&gt; {\n throw new TypeError(&#39;Wrong value&#39;);\n },\n {\n name: &#39;TypeError&#39;,\n message: &#39;Wrong value&#39;\n }\n );\n})();\n</code></pre>\n<pre><code class=\"lang-js\">assert.rejects(\n Promise.reject(new Error(&#39;Wrong value&#39;)),\n Error\n).then(() =&gt; {\n // ...\n});\n</code></pre>\n<p>Note that <code>error</code> cannot be a string. If a string is provided as the second\nargument, then <code>error</code> is assumed to be omitted and the string will be used for\n<code>message</code> instead. This can lead to easy-to-miss mistakes. Please read the\nexample in <a href=\"#assert_assert_throws_block_error_message\"><code>assert.throws()</code></a> carefully if using a string as the second\nargument gets considered.</p>\n"
},
{
"textRaw": "assert.strictEqual(actual, expected[, message])",
"type": "method",
"name": "strictEqual",
"meta": {
"added": [
"v0.1.21"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/17003",
"description": "Used comparison changed from Strict Equality to `Object.is()`"
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`actual` {any} ",
"name": "actual",
"type": "any"
},
{
"textRaw": "`expected` {any} ",
"name": "expected",
"type": "any"
},
{
"textRaw": "`message` {string|Error} ",
"name": "message",
"type": "string|Error",
"optional": true
}
]
},
{
"params": [
{
"name": "actual"
},
{
"name": "expected"
},
{
"name": "message",
"optional": true
}
]
}
],
"desc": "<p>Tests strict equality between the <code>actual</code> and <code>expected</code> parameters as\ndetermined by the <a href=\"https://tc39.github.io/ecma262/#sec-samevalue\">SameValue Comparison</a>.</p>\n<pre><code class=\"lang-js\">const assert = require(&#39;assert&#39;).strict;\n\nassert.strictEqual(1, 2);\n// AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:\n// + expected - actual\n// - 1\n// + 2\n\nassert.strictEqual(1, 1);\n// OK\n\nassert.strictEqual(1, &#39;1&#39;);\n// AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:\n// + expected - actual\n// - 1\n// + &#39;1&#39;\n</code></pre>\n<p>If the values are not strictly equal, an <code>AssertionError</code> is thrown with a\n<code>message</code> property set equal to the value of the <code>message</code> parameter. If the\n<code>message</code> parameter is undefined, a default error message is assigned. If the\n<code>message</code> parameter is an instance of an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> then it will be thrown\ninstead of the <code>AssertionError</code>.</p>\n"
},
{
"textRaw": "assert.throws(block[, error][, message])",
"type": "method",
"name": "throws",
"meta": {
"added": [
"v0.1.21"
],
"changes": [
{
"version": "v10.2.0",
"pr-url": "https://github.com/nodejs/node/pull/20485",
"description": "The `error` parameter can be an object containing regular expressions now."
},
{
"version": "v9.9.0",
"pr-url": "https://github.com/nodejs/node/pull/17584",
"description": "The `error` parameter can now be an object as well."
},
{
"version": "v4.2.0",
"pr-url": "https://github.com/nodejs/node/pull/3276",
"description": "The `error` parameter can now be an arrow function."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`block` {Function} ",
"name": "block",
"type": "Function"
},
{
"textRaw": "`error` {RegExp|Function|Object|Error} ",
"name": "error",
"type": "RegExp|Function|Object|Error",
"optional": true
},
{
"textRaw": "`message` {string|Error} ",
"name": "message",
"type": "string|Error",
"optional": true
}
]
},
{
"params": [
{
"name": "block"
},
{
"name": "error",
"optional": true
},
{
"name": "message",
"optional": true
}
]
}
],
"desc": "<p>Expects the function <code>block</code> to throw an error.</p>\n<p>If specified, <code>error</code> can be a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes\"><code>Class</code></a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\"><code>RegExp</code></a>, a validation function,\na validation object where each property will be tested for strict deep equality,\nor an instance of error where each property will be tested for strict deep\nequality including the non-enumerable <code>message</code> and <code>name</code> properties. When\nusing an object, it is also possible to use a regular expression, when\nvalidating against a string property. See below for examples.</p>\n<p>If specified, <code>message</code> will be the message provided by the <code>AssertionError</code> if\nthe block fails to throw.</p>\n<p>Custom validation object/error instance:</p>\n<pre><code class=\"lang-js\">const err = new TypeError(&#39;Wrong value&#39;);\nerr.code = 404;\nerr.foo = &#39;bar&#39;;\nerr.info = {\n nested: true,\n baz: &#39;text&#39;\n};\nerr.reg = /abc/i;\n\nassert.throws(\n () =&gt; {\n throw err;\n },\n {\n name: &#39;TypeError&#39;,\n message: &#39;Wrong value&#39;,\n info: {\n nested: true,\n baz: &#39;text&#39;\n }\n // Note that only properties on the validation object will be tested for.\n // Using nested objects requires all properties to be present. Otherwise\n // the validation is going to fail.\n }\n);\n\n// Using regular expressions to validate error properties:\nassert.throws(\n () =&gt; {\n throw err;\n },\n {\n // The `name` and `message` properties are strings and using regular\n // expressions on those will match against the string. If they fail, an\n // error is thrown.\n name: /^TypeError$/,\n message: /Wrong/,\n foo: &#39;bar&#39;,\n info: {\n nested: true,\n // It is not possible to use regular expressions for nested properties!\n baz: &#39;text&#39;\n },\n // The `reg` property contains a regular expression and only if the\n // validation object contains an identical regular expression, it is going\n // to pass.\n reg: /abc/i\n }\n);\n\n// Fails due to the different `message` and `name` properties:\nassert.throws(\n () =&gt; {\n const otherErr = new Error(&#39;Not found&#39;);\n otherErr.code = 404;\n throw otherErr;\n },\n err // This tests for `message`, `name` and `code`.\n);\n</code></pre>\n<p>Validate instanceof using constructor:</p>\n<pre><code class=\"lang-js\">assert.throws(\n () =&gt; {\n throw new Error(&#39;Wrong value&#39;);\n },\n Error\n);\n</code></pre>\n<p>Validate error message using <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\"><code>RegExp</code></a>:</p>\n<p>Using a regular expression runs <code>.toString</code> on the error object, and will\ntherefore also include the error name.</p>\n<pre><code class=\"lang-js\">assert.throws(\n () =&gt; {\n throw new Error(&#39;Wrong value&#39;);\n },\n /^Error: Wrong value$/\n);\n</code></pre>\n<p>Custom error validation:</p>\n<pre><code class=\"lang-js\">assert.throws(\n () =&gt; {\n throw new Error(&#39;Wrong value&#39;);\n },\n function(err) {\n if ((err instanceof Error) &amp;&amp; /value/.test(err)) {\n return true;\n }\n },\n &#39;unexpected error&#39;\n);\n</code></pre>\n<p>Note that <code>error</code> cannot be a string. If a string is provided as the second\nargument, then <code>error</code> is assumed to be omitted and the string will be used for\n<code>message</code> instead. This can lead to easy-to-miss mistakes. Using the same\nmessage as the thrown error message is going to result in an\n<code>ERR_AMBIGUOUS_ARGUMENT</code> error. Please read the example below carefully if using\na string as the second argument gets considered:</p>\n<!-- eslint-disable no-restricted-syntax -->\n<pre><code class=\"lang-js\">function throwingFirst() {\n throw new Error(&#39;First&#39;);\n}\nfunction throwingSecond() {\n throw new Error(&#39;Second&#39;);\n}\nfunction notThrowing() {}\n\n// The second argument is a string and the input function threw an Error.\n// The first case will not throw as it does not match for the error message\n// thrown by the input function!\nassert.throws(throwingFirst, &#39;Second&#39;);\n// In the next example the message has no benefit over the message from the\n// error and since it is not clear if the user intended to actually match\n// against the error message, Node.js thrown an `ERR_AMBIGUOUS_ARGUMENT` error.\nassert.throws(throwingSecond, &#39;Second&#39;);\n// Throws an error:\n// TypeError [ERR_AMBIGUOUS_ARGUMENT]\n\n// The string is only used (as message) in case the function does not throw:\nassert.throws(notThrowing, &#39;Second&#39;);\n// AssertionError [ERR_ASSERTION]: Missing expected exception: Second\n\n// If it was intended to match for the error message do this instead:\nassert.throws(throwingSecond, /Second$/);\n// Does not throw because the error messages match.\nassert.throws(throwingFirst, /Second$/);\n// Throws an error:\n// Error: First\n// at throwingFirst (repl:2:9)\n</code></pre>\n<p>Due to the confusing notation, it is recommended not to use a string as the\nsecond argument. This might lead to difficult-to-spot errors.</p>\n"
}
],
"type": "module",
"displayName": "Assert"
},
{
"textRaw": "Async Hooks",
"name": "async_hooks",
"introduced_in": "v8.1.0",
"stability": 1,
"stabilityText": "Experimental",
"desc": "<p>The <code>async_hooks</code> module provides an API to register callbacks tracking the\nlifetime of asynchronous resources created inside a Node.js application.\nIt can be accessed using:</p>\n<pre><code class=\"lang-js\">const async_hooks = require(&#39;async_hooks&#39;);\n</code></pre>\n",
"modules": [
{
"textRaw": "Terminology",
"name": "terminology",
"desc": "<p>An asynchronous resource represents an object with an associated callback.\nThis callback may be called multiple times, for example, the <code>&#39;connection&#39;</code>\nevent in <code>net.createServer()</code>, or just a single time like in <code>fs.open()</code>.\nA resource can also be closed before the callback is called. <code>AsyncHook</code> does\nnot explicitly distinguish between these different cases but will represent them\nas the abstract concept that is a resource.</p>\n<p>If <a href=\"worker_threads.html#worker_threads_class_worker\"><code>Worker</code></a>s are used, each thread has an independent <code>async_hooks</code>\ninterface, and each thread will use a new set of async IDs.</p>\n",
"type": "module",
"displayName": "Terminology"
},
{
"textRaw": "Public API",
"name": "public_api",
"modules": [
{
"textRaw": "Overview",
"name": "overview",
"desc": "<p>Following is a simple overview of the public API.</p>\n<pre><code class=\"lang-js\">const async_hooks = require(&#39;async_hooks&#39;);\n\n// Return the ID of the current execution context.\nconst eid = async_hooks.executionAsyncId();\n\n// Return the ID of the handle responsible for triggering the callback of the\n// current execution scope to call.\nconst tid = async_hooks.triggerAsyncId();\n\n// Create a new AsyncHook instance. All of these callbacks are optional.\nconst asyncHook =\n async_hooks.createHook({ init, before, after, destroy, promiseResolve });\n\n// Allow callbacks of this AsyncHook instance to call. This is not an implicit\n// action after running the constructor, and must be explicitly run to begin\n// executing callbacks.\nasyncHook.enable();\n\n// Disable listening for new asynchronous events.\nasyncHook.disable();\n\n//\n// The following are the callbacks that can be passed to createHook().\n//\n\n// init is called during object construction. The resource may not have\n// completed construction when this callback runs, therefore all fields of the\n// resource referenced by &quot;asyncId&quot; may not have been populated.\nfunction init(asyncId, type, triggerAsyncId, resource) { }\n\n// before is called just before the resource&#39;s callback is called. It can be\n// called 0-N times for handles (e.g. TCPWrap), and will be called exactly 1\n// time for requests (e.g. FSReqWrap).\nfunction before(asyncId) { }\n\n// after is called just after the resource&#39;s callback has finished.\nfunction after(asyncId) { }\n\n// destroy is called when an AsyncWrap instance is destroyed.\nfunction destroy(asyncId) { }\n\n// promiseResolve is called only for promise resources, when the\n// `resolve` function passed to the `Promise` constructor is invoked\n// (either directly or through other means of resolving a promise).\nfunction promiseResolve(asyncId) { }\n</code></pre>\n",
"methods": [
{
"textRaw": "async_hooks.createHook(callbacks)",
"type": "method",
"name": "createHook",
"meta": {
"added": [
"v8.1.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {AsyncHook} Instance used for disabling and enabling hooks ",
"name": "return",
"type": "AsyncHook",
"desc": "Instance used for disabling and enabling hooks"
},
"params": [
{
"textRaw": "`callbacks` {Object} The [Hook Callbacks][] to register ",
"options": [
{
"textRaw": "`init` {Function} The [`init` callback][]. ",
"name": "init",
"type": "Function",
"desc": "The [`init` callback][]."
},
{
"textRaw": "`before` {Function} The [`before` callback][]. ",
"name": "before",
"type": "Function",
"desc": "The [`before` callback][]."
},
{
"textRaw": "`after` {Function} The [`after` callback][]. ",
"name": "after",
"type": "Function",
"desc": "The [`after` callback][]."
},
{
"textRaw": "`destroy` {Function} The [`destroy` callback][]. ",
"name": "destroy",
"type": "Function",
"desc": "The [`destroy` callback][]."
}
],
"name": "callbacks",
"type": "Object",
"desc": "The [Hook Callbacks][] to register"
}
]
},
{
"params": [
{
"name": "callbacks"
}
]
}
],
"desc": "<p>Registers functions to be called for different lifetime events of each async\noperation.</p>\n<p>The callbacks <code>init()</code>/<code>before()</code>/<code>after()</code>/<code>destroy()</code> are called for the\nrespective asynchronous event during a resource&#39;s lifetime.</p>\n<p>All callbacks are optional. For example, if only resource cleanup needs to\nbe tracked, then only the <code>destroy</code> callback needs to be passed. The\nspecifics of all functions that can be passed to <code>callbacks</code> is in the\n<a href=\"#async_hooks_hook_callbacks\">Hook Callbacks</a> section.</p>\n<pre><code class=\"lang-js\">const async_hooks = require(&#39;async_hooks&#39;);\n\nconst asyncHook = async_hooks.createHook({\n init(asyncId, type, triggerAsyncId, resource) { },\n destroy(asyncId) { }\n});\n</code></pre>\n<p>Note that the callbacks will be inherited via the prototype chain:</p>\n<pre><code class=\"lang-js\">class MyAsyncCallbacks {\n init(asyncId, type, triggerAsyncId, resource) { }\n destroy(asyncId) {}\n}\n\nclass MyAddedCallbacks extends MyAsyncCallbacks {\n before(asyncId) { }\n after(asyncId) { }\n}\n\nconst asyncHook = async_hooks.createHook(new MyAddedCallbacks());\n</code></pre>\n",
"modules": [
{
"textRaw": "Error Handling",
"name": "error_handling",
"desc": "<p>If any <code>AsyncHook</code> callbacks throw, the application will print the stack trace\nand exit. The exit path does follow that of an uncaught exception, but\nall <code>&#39;uncaughtException&#39;</code> listeners are removed, thus forcing the process to\nexit. The <code>&#39;exit&#39;</code> callbacks will still be called unless the application is run\nwith <code>--abort-on-uncaught-exception</code>, in which case a stack trace will be\nprinted and the application exits, leaving a core file.</p>\n<p>The reason for this error handling behavior is that these callbacks are running\nat potentially volatile points in an object&#39;s lifetime, for example during\nclass construction and destruction. Because of this, it is deemed necessary to\nbring down the process quickly in order to prevent an unintentional abort in the\nfuture. This is subject to change in the future if a comprehensive analysis is\nperformed to ensure an exception can follow the normal control flow without\nunintentional side effects.</p>\n",
"type": "module",
"displayName": "Error Handling"
},
{
"textRaw": "Printing in AsyncHooks callbacks",
"name": "printing_in_asynchooks_callbacks",
"desc": "<p>Because printing to the console is an asynchronous operation, <code>console.log()</code>\nwill cause the AsyncHooks callbacks to be called. Using <code>console.log()</code> or\nsimilar asynchronous operations inside an AsyncHooks callback function will thus\ncause an infinite recursion. An easy solution to this when debugging is to use a\nsynchronous logging operation such as <code>fs.writeSync(1, msg)</code>. This will print to\nstdout because <code>1</code> is the file descriptor for stdout and will not invoke\nAsyncHooks recursively because it is synchronous.</p>\n<pre><code class=\"lang-js\">const fs = require(&#39;fs&#39;);\nconst util = require(&#39;util&#39;);\n\nfunction debug(...args) {\n // use a function like this one when debugging inside an AsyncHooks callback\n fs.writeSync(1, `${util.format(...args)}\\n`);\n}\n</code></pre>\n<p>If an asynchronous operation is needed for logging, it is possible to keep\ntrack of what caused the asynchronous operation using the information\nprovided by AsyncHooks itself. The logging should then be skipped when\nit was the logging itself that caused AsyncHooks callback to call. By\ndoing this the otherwise infinite recursion is broken.</p>\n",
"type": "module",
"displayName": "Printing in AsyncHooks callbacks"
}
]
},
{
"textRaw": "asyncHook.enable()",
"type": "method",
"name": "enable",
"signatures": [
{
"return": {
"textRaw": "Returns: {AsyncHook} A reference to `asyncHook`. ",
"name": "return",
"type": "AsyncHook",
"desc": "A reference to `asyncHook`."
},
"params": []
},
{
"params": []
}
],
"desc": "<p>Enable the callbacks for a given <code>AsyncHook</code> instance. If no callbacks are\nprovided enabling is a noop.</p>\n<p>The <code>AsyncHook</code> instance is disabled by default. If the <code>AsyncHook</code> instance\nshould be enabled immediately after creation, the following pattern can be used.</p>\n<pre><code class=\"lang-js\">const async_hooks = require(&#39;async_hooks&#39;);\n\nconst hook = async_hooks.createHook(callbacks).enable();\n</code></pre>\n"
},
{
"textRaw": "asyncHook.disable()",
"type": "method",
"name": "disable",
"signatures": [
{
"return": {
"textRaw": "Returns: {AsyncHook} A reference to `asyncHook`. ",
"name": "return",
"type": "AsyncHook",
"desc": "A reference to `asyncHook`."
},
"params": []
},
{
"params": []
}
],
"desc": "<p>Disable the callbacks for a given <code>AsyncHook</code> instance from the global pool of\n<code>AsyncHook</code> callbacks to be executed. Once a hook has been disabled it will not\nbe called again until enabled.</p>\n<p>For API consistency <code>disable()</code> also returns the <code>AsyncHook</code> instance.</p>\n"
},
{
"textRaw": "async_hooks.executionAsyncId()",
"type": "method",
"name": "executionAsyncId",
"meta": {
"added": [
"v8.1.0"
],
"changes": [
{
"version": "v8.2.0",
"pr-url": "https://github.com/nodejs/node/pull/13490",
"description": "Renamed from `currentId`"
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {number} The `asyncId` of the current execution context. Useful to track when something calls. ",
"name": "return",
"type": "number",
"desc": "The `asyncId` of the current execution context. Useful to track when something calls."
},
"params": []
},
{
"params": []
}
],
"desc": "<pre><code class=\"lang-js\">const async_hooks = require(&#39;async_hooks&#39;);\n\nconsole.log(async_hooks.executionAsyncId()); // 1 - bootstrap\nfs.open(path, &#39;r&#39;, (err, fd) =&gt; {\n console.log(async_hooks.executionAsyncId()); // 6 - open()\n});\n</code></pre>\n<p>The ID returned from <code>executionAsyncId()</code> is related to execution timing, not\ncausality (which is covered by <code>triggerAsyncId()</code>):</p>\n<pre><code class=\"lang-js\">const server = net.createServer(function onConnection(conn) {\n // Returns the ID of the server, not of the new connection, because the\n // onConnection callback runs in the execution scope of the server&#39;s\n // MakeCallback().\n async_hooks.executionAsyncId();\n\n}).listen(port, function onListening() {\n // Returns the ID of a TickObject (i.e. process.nextTick()) because all\n // callbacks passed to .listen() are wrapped in a nextTick().\n async_hooks.executionAsyncId();\n});\n</code></pre>\n<p>Note that promise contexts may not get precise <code>executionAsyncIds</code> by default.\nSee the section on <a href=\"#async_hooks_promise_execution_tracking\">promise execution tracking</a>.</p>\n"
},
{
"textRaw": "async_hooks.triggerAsyncId()",
"type": "method",
"name": "triggerAsyncId",
"signatures": [
{
"return": {
"textRaw": "Returns: {number} The ID of the resource responsible for calling the callback that is currently being executed. ",
"name": "return",
"type": "number",
"desc": "The ID of the resource responsible for calling the callback that is currently being executed."
},
"params": []
},
{
"params": []
}
],
"desc": "<pre><code class=\"lang-js\">const server = net.createServer((conn) =&gt; {\n // The resource that caused (or triggered) this callback to be called\n // was that of the new connection. Thus the return value of triggerAsyncId()\n // is the asyncId of &quot;conn&quot;.\n async_hooks.triggerAsyncId();\n\n}).listen(port, () =&gt; {\n // Even though all callbacks passed to .listen() are wrapped in a nextTick()\n // the callback itself exists because the call to the server&#39;s .listen()\n // was made. So the return value would be the ID of the server.\n async_hooks.triggerAsyncId();\n});\n</code></pre>\n<p>Note that promise contexts may not get valid <code>triggerAsyncId</code>s by default. See\nthe section on <a href=\"#async_hooks_promise_execution_tracking\">promise execution tracking</a>.</p>\n"
}
],
"modules": [
{
"textRaw": "Hook Callbacks",
"name": "hook_callbacks",
"desc": "<p>Key events in the lifetime of asynchronous events have been categorized into\nfour areas: instantiation, before/after the callback is called, and when the\ninstance is destroyed.</p>\n",
"methods": [
{
"textRaw": "init(asyncId, type, triggerAsyncId, resource)",
"type": "method",
"name": "init",
"signatures": [
{
"params": [
{
"textRaw": "`asyncId` {number} A unique ID for the async resource. ",
"name": "asyncId",
"type": "number",
"desc": "A unique ID for the async resource."
},
{
"textRaw": "`type` {string} The type of the async resource. ",
"name": "type",
"type": "string",
"desc": "The type of the async resource."
},
{
"textRaw": "`triggerAsyncId` {number} The unique ID of the async resource in whose execution context this async resource was created. ",
"name": "triggerAsyncId",
"type": "number",
"desc": "The unique ID of the async resource in whose execution context this async resource was created."
},
{
"textRaw": "`resource` {Object} Reference to the resource representing the async operation, needs to be released during _destroy_. ",
"name": "resource",
"type": "Object",
"desc": "Reference to the resource representing the async operation, needs to be released during _destroy_."
}
]
},
{
"params": [
{
"name": "asyncId"
},
{
"name": "type"
},
{
"name": "triggerAsyncId"
},
{
"name": "resource"
}
]
}
],
"desc": "<p>Called when a class is constructed that has the <em>possibility</em> to emit an\nasynchronous event. This <em>does not</em> mean the instance must call\n<code>before</code>/<code>after</code> before <code>destroy</code> is called, only that the possibility\nexists.</p>\n<p>This behavior can be observed by doing something like opening a resource then\nclosing it before the resource can be used. The following snippet demonstrates\nthis.</p>\n<pre><code class=\"lang-js\">require(&#39;net&#39;).createServer().listen(function() { this.close(); });\n// OR\nclearTimeout(setTimeout(() =&gt; {}, 10));\n</code></pre>\n<p>Every new resource is assigned an ID that is unique within the scope of the\ncurrent Node.js instance.</p>\n",
"modules": [
{
"textRaw": "`type`",
"name": "`type`",
"desc": "<p>The <code>type</code> is a string identifying the type of resource that caused\n<code>init</code> to be called. Generally, it will correspond to the name of the\nresource&#39;s constructor.</p>\n<pre><code class=\"lang-text\">FSEVENTWRAP, FSREQWRAP, GETADDRINFOREQWRAP, GETNAMEINFOREQWRAP, HTTPPARSER,\nJSSTREAM, PIPECONNECTWRAP, PIPEWRAP, PROCESSWRAP, QUERYWRAP, SHUTDOWNWRAP,\nSIGNALWRAP, STATWATCHER, TCPCONNECTWRAP, TCPSERVER, TCPWRAP, TTYWRAP,\nUDPSENDWRAP, UDPWRAP, WRITEWRAP, ZLIB, SSLCONNECTION, PBKDF2REQUEST,\nRANDOMBYTESREQUEST, TLSWRAP, Timeout, Immediate, TickObject\n</code></pre>\n<p>There is also the <code>PROMISE</code> resource type, which is used to track <code>Promise</code>\ninstances and asynchronous work scheduled by them.</p>\n<p>Users are able to define their own <code>type</code> when using the public embedder API.</p>\n<p>It is possible to have type name collisions. Embedders are encouraged to use\nunique prefixes, such as the npm package name, to prevent collisions when\nlistening to the hooks.</p>\n",
"type": "module",
"displayName": "`type`"
},
{
"textRaw": "`triggerAsyncId`",
"name": "`triggerasyncid`",
"desc": "<p><code>triggerAsyncId</code> is the <code>asyncId</code> of the resource that caused (or &quot;triggered&quot;)\nthe new resource to initialize and that caused <code>init</code> to call. This is different\nfrom <code>async_hooks.executionAsyncId()</code> that only shows <em>when</em> a resource was\ncreated, while <code>triggerAsyncId</code> shows <em>why</em> a resource was created.</p>\n<p>The following is a simple demonstration of <code>triggerAsyncId</code>:</p>\n<pre><code class=\"lang-js\">async_hooks.createHook({\n init(asyncId, type, triggerAsyncId) {\n const eid = async_hooks.executionAsyncId();\n fs.writeSync(\n 1, `${type}(${asyncId}): trigger: ${triggerAsyncId} execution: ${eid}\\n`);\n }\n}).enable();\n\nrequire(&#39;net&#39;).createServer((conn) =&gt; {}).listen(8080);\n</code></pre>\n<p>Output when hitting the server with <code>nc localhost 8080</code>:</p>\n<pre><code class=\"lang-console\">TCPSERVERWRAP(2): trigger: 1 execution: 1\nTCPWRAP(4): trigger: 2 execution: 0\n</code></pre>\n<p>The <code>TCPSERVERWRAP</code> is the server which receives the connections.</p>\n<p>The <code>TCPWRAP</code> is the new connection from the client. When a new\nconnection is made, the <code>TCPWrap</code> instance is immediately constructed. This\nhappens outside of any JavaScript stack. (An <code>executionAsyncId()</code> of <code>0</code> means\nthat it is being executed from C++ with no JavaScript stack above it.) With only\nthat information, it would be impossible to link resources together in\nterms of what caused them to be created, so <code>triggerAsyncId</code> is given the task\nof propagating what resource is responsible for the new resource&#39;s existence.</p>\n",
"type": "module",
"displayName": "`triggerAsyncId`"
},
{
"textRaw": "`resource`",
"name": "`resource`",
"desc": "<p><code>resource</code> is an object that represents the actual async resource that has\nbeen initialized. This can contain useful information that can vary based on\nthe value of <code>type</code>. For instance, for the <code>GETADDRINFOREQWRAP</code> resource type,\n<code>resource</code> provides the hostname used when looking up the IP address for the\nhostname in <code>net.Server.listen()</code>. The API for accessing this information is\ncurrently not considered public, but using the Embedder API, users can provide\nand document their own resource objects. For example, such a resource object\ncould contain the SQL query being executed.</p>\n<p>In the case of Promises, the <code>resource</code> object will have <code>promise</code> property\nthat refers to the <code>Promise</code> that is being initialized, and an\n<code>isChainedPromise</code> property, set to <code>true</code> if the promise has a parent promise,\nand <code>false</code> otherwise. For example, in the case of <code>b = a.then(handler)</code>, <code>a</code> is\nconsidered a parent <code>Promise</code> of <code>b</code>. Here, <code>b</code> is considered a chained promise.</p>\n<p>In some cases the resource object is reused for performance reasons, it is\nthus not safe to use it as a key in a <code>WeakMap</code> or add properties to it.</p>\n",
"type": "module",
"displayName": "`resource`"
},
{
"textRaw": "Asynchronous context example",
"name": "asynchronous_context_example",
"desc": "<p>The following is an example with additional information about the calls to\n<code>init</code> between the <code>before</code> and <code>after</code> calls, specifically what the\ncallback to <code>listen()</code> will look like. The output formatting is slightly more\nelaborate to make calling context easier to see.</p>\n<pre><code class=\"lang-js\">let indent = 0;\nasync_hooks.createHook({\n init(asyncId, type, triggerAsyncId) {\n const eid = async_hooks.executionAsyncId();\n const indentStr = &#39; &#39;.repeat(indent);\n fs.writeSync(\n 1,\n `${indentStr}${type}(${asyncId}):` +\n ` trigger: ${triggerAsyncId} execution: ${eid}\\n`);\n },\n before(asyncId) {\n const indentStr = &#39; &#39;.repeat(indent);\n fs.writeSync(1, `${indentStr}before: ${asyncId}\\n`);\n indent += 2;\n },\n after(asyncId) {\n indent -= 2;\n const indentStr = &#39; &#39;.repeat(indent);\n fs.writeSync(1, `${indentStr}after: ${asyncId}\\n`);\n },\n destroy(asyncId) {\n const indentStr = &#39; &#39;.repeat(indent);\n fs.writeSync(1, `${indentStr}destroy: ${asyncId}\\n`);\n },\n}).enable();\n\nrequire(&#39;net&#39;).createServer(() =&gt; {}).listen(8080, () =&gt; {\n // Let&#39;s wait 10ms before logging the server started.\n setTimeout(() =&gt; {\n console.log(&#39;&gt;&gt;&gt;&#39;, async_hooks.executionAsyncId());\n }, 10);\n});\n</code></pre>\n<p>Output from only starting the server:</p>\n<pre><code class=\"lang-console\">TCPSERVERWRAP(2): trigger: 1 execution: 1\nTickObject(3): trigger: 2 execution: 1\nbefore: 3\n Timeout(4): trigger: 3 execution: 3\n TIMERWRAP(5): trigger: 3 execution: 3\nafter: 3\ndestroy: 3\nbefore: 5\n before: 4\n TTYWRAP(6): trigger: 4 execution: 4\n SIGNALWRAP(7): trigger: 4 execution: 4\n TTYWRAP(8): trigger: 4 execution: 4\n&gt;&gt;&gt; 4\n TickObject(9): trigger: 4 execution: 4\n after: 4\nafter: 5\nbefore: 9\nafter: 9\ndestroy: 4\ndestroy: 9\ndestroy: 5\n</code></pre>\n<p>As illustrated in the example, <code>executionAsyncId()</code> and <code>execution</code> each specify\nthe value of the current execution context; which is delineated by calls to\n<code>before</code> and <code>after</code>.</p>\n<p>Only using <code>execution</code> to graph resource allocation results in the following:</p>\n<pre><code class=\"lang-console\">TTYWRAP(6) -&gt; Timeout(4) -&gt; TIMERWRAP(5) -&gt; TickObject(3) -&gt; root(1)\n</code></pre>\n<p>The <code>TCPSERVERWRAP</code> is not part of this graph, even though it was the reason for\n<code>console.log()</code> being called. This is because binding to a port without a\nhostname is a <em>synchronous</em> operation, but to maintain a completely asynchronous\nAPI the user&#39;s callback is placed in a <code>process.nextTick()</code>.</p>\n<p>The graph only shows <em>when</em> a resource was created, not <em>why</em>, so to track\nthe <em>why</em> use <code>triggerAsyncId</code>.</p>\n",
"type": "module",
"displayName": "Asynchronous context example"
}
]
},
{
"textRaw": "before(asyncId)",
"type": "method",
"name": "before",
"signatures": [
{
"params": [
{
"textRaw": "`asyncId` {number} ",
"name": "asyncId",
"type": "number"
}
]
},
{
"params": [
{
"name": "asyncId"
}
]
}
],
"desc": "<p>When an asynchronous operation is initiated (such as a TCP server receiving a\nnew connection) or completes (such as writing data to disk) a callback is\ncalled to notify the user. The <code>before</code> callback is called just before said\ncallback is executed. <code>asyncId</code> is the unique identifier assigned to the\nresource about to execute the callback.</p>\n<p>The <code>before</code> callback will be called 0 to N times. The <code>before</code> callback\nwill typically be called 0 times if the asynchronous operation was cancelled\nor, for example, if no connections are received by a TCP server. Persistent\nasynchronous resources like a TCP server will typically call the <code>before</code>\ncallback multiple times, while other operations like <code>fs.open()</code> will call\nit only once.</p>\n"
},
{
"textRaw": "after(asyncId)",
"type": "method",
"name": "after",
"signatures": [
{
"params": [
{
"textRaw": "`asyncId` {number} ",
"name": "asyncId",
"type": "number"
}
]
},
{
"params": [
{
"name": "asyncId"
}
]
}
],
"desc": "<p>Called immediately after the callback specified in <code>before</code> is completed.</p>\n<p>If an uncaught exception occurs during execution of the callback, then <code>after</code>\nwill run <em>after</em> the <code>&#39;uncaughtException&#39;</code> event is emitted or a <code>domain</code>&#39;s\nhandler runs.</p>\n"
},
{
"textRaw": "destroy(asyncId)",
"type": "method",
"name": "destroy",
"signatures": [
{
"params": [
{
"textRaw": "`asyncId` {number} ",
"name": "asyncId",
"type": "number"
}
]
},
{
"params": [
{
"name": "asyncId"
}
]
}
],
"desc": "<p>Called after the resource corresponding to <code>asyncId</code> is destroyed. It is also\ncalled asynchronously from the embedder API <code>emitDestroy()</code>.</p>\n<p>Some resources depend on garbage collection for cleanup, so if a reference is\nmade to the <code>resource</code> object passed to <code>init</code> it is possible that <code>destroy</code>\nwill never be called, causing a memory leak in the application. If the resource\ndoes not depend on garbage collection, then this will not be an issue.</p>\n"
},
{
"textRaw": "promiseResolve(asyncId)",
"type": "method",
"name": "promiseResolve",
"signatures": [
{
"params": [
{
"textRaw": "`asyncId` {number} ",
"name": "asyncId",
"type": "number"
}
]
},
{
"params": [
{
"name": "asyncId"
}
]
}
],
"desc": "<p>Called when the <code>resolve</code> function passed to the <code>Promise</code> constructor is\ninvoked (either directly or through other means of resolving a promise).</p>\n<p>Note that <code>resolve()</code> does not do any observable synchronous work.</p>\n<p>The <code>Promise</code> is not necessarily fulfilled or rejected at this point if the\n<code>Promise</code> was resolved by assuming the state of another <code>Promise</code>.</p>\n<pre><code class=\"lang-js\">new Promise((resolve) =&gt; resolve(true)).then((a) =&gt; {});\n</code></pre>\n<p>calls the following callbacks:</p>\n<pre><code class=\"lang-text\">init for PROMISE with id 5, trigger id: 1\n promise resolve 5 # corresponds to resolve(true)\ninit for PROMISE with id 6, trigger id: 5 # the Promise returned by then()\n before 6 # the then() callback is entered\n promise resolve 6 # the then() callback resolves the promise by returning\n after 6\n</code></pre>\n"
}
],
"type": "module",
"displayName": "Hook Callbacks"
}
],
"type": "module",
"displayName": "Overview"
}
],
"type": "module",
"displayName": "Public API"
},
{
"textRaw": "Promise execution tracking",
"name": "promise_execution_tracking",
"desc": "<p>By default, promise executions are not assigned <code>asyncId</code>s due to the relatively\nexpensive nature of the <a href=\"https://docs.google.com/document/d/1rda3yKGHimKIhg5YeoAmCOtyURgsbTH_qaYR79FELlk\">promise introspection API</a> provided by\nV8. This means that programs using promises or <code>async</code>/<code>await</code> will not get\ncorrect execution and trigger ids for promise callback contexts by default.</p>\n<p>Here&#39;s an example:</p>\n<pre><code class=\"lang-js\">const ah = require(&#39;async_hooks&#39;);\nPromise.resolve(1729).then(() =&gt; {\n console.log(`eid ${ah.executionAsyncId()} tid ${ah.triggerAsyncId()}`);\n});\n// produces:\n// eid 1 tid 0\n</code></pre>\n<p>Observe that the <code>then()</code> callback claims to have executed in the context of the\nouter scope even though there was an asynchronous hop involved. Also note that\nthe <code>triggerAsyncId</code> value is <code>0</code>, which means that we are missing context about\nthe resource that caused (triggered) the <code>then()</code> callback to be executed.</p>\n<p>Installing async hooks via <code>async_hooks.createHook</code> enables promise execution\ntracking. Example:</p>\n<pre><code class=\"lang-js\">const ah = require(&#39;async_hooks&#39;);\nah.createHook({ init() {} }).enable(); // forces PromiseHooks to be enabled.\nPromise.resolve(1729).then(() =&gt; {\n console.log(`eid ${ah.executionAsyncId()} tid ${ah.triggerAsyncId()}`);\n});\n// produces:\n// eid 7 tid 6\n</code></pre>\n<p>In this example, adding any actual hook function enabled the tracking of\npromises. There are two promises in the example above; the promise created by\n<code>Promise.resolve()</code> and the promise returned by the call to <code>then()</code>. In the\nexample above, the first promise got the <code>asyncId</code> <code>6</code> and the latter got\n<code>asyncId</code> <code>7</code>. During the execution of the <code>then()</code> callback, we are executing\nin the context of promise with <code>asyncId</code> <code>7</code>. This promise was triggered by\nasync resource <code>6</code>.</p>\n<p>Another subtlety with promises is that <code>before</code> and <code>after</code> callbacks are run\nonly on chained promises. That means promises not created by <code>then()</code>/<code>catch()</code>\nwill not have the <code>before</code> and <code>after</code> callbacks fired on them. For more details\nsee the details of the V8 <a href=\"https://docs.google.com/document/d/1rda3yKGHimKIhg5YeoAmCOtyURgsbTH_qaYR79FELlk\">PromiseHooks</a> API.</p>\n",
"type": "module",
"displayName": "Promise execution tracking"
},
{
"textRaw": "JavaScript Embedder API",
"name": "javascript_embedder_api",
"desc": "<p>Library developers that handle their own asynchronous resources performing tasks\nlike I/O, connection pooling, or managing callback queues may use the\n<code>AsyncWrap</code> JavaScript API so that all the appropriate callbacks are called.</p>\n",
"classes": [
{
"textRaw": "Class: AsyncResource",
"type": "class",
"name": "AsyncResource",
"desc": "<p>The class <code>AsyncResource</code> is designed to be extended by the embedder&#39;s async\nresources. Using this, users can easily trigger the lifetime events of their\nown resources.</p>\n<p>The <code>init</code> hook will trigger when an <code>AsyncResource</code> is instantiated.</p>\n<p>The following is an overview of the <code>AsyncResource</code> API.</p>\n<pre><code class=\"lang-js\">const { AsyncResource, executionAsyncId } = require(&#39;async_hooks&#39;);\n\n// AsyncResource() is meant to be extended. Instantiating a\n// new AsyncResource() also triggers init. If triggerAsyncId is omitted then\n// async_hook.executionAsyncId() is used.\nconst asyncResource = new AsyncResource(\n type, { triggerAsyncId: executionAsyncId(), requireManualDestroy: false }\n);\n\n// Run a function in the execution context of the resource. This will\n// * establish the context of the resource\n// * trigger the AsyncHooks before callbacks\n// * call the provided function `fn` with the supplied arguments\n// * trigger the AsyncHooks after callbacks\n// * restore the original execution context\nasyncResource.runInAsyncScope(fn, thisArg, ...args);\n\n// Call AsyncHooks destroy callbacks.\nasyncResource.emitDestroy();\n\n// Return the unique ID assigned to the AsyncResource instance.\nasyncResource.asyncId();\n\n// Return the trigger ID for the AsyncResource instance.\nasyncResource.triggerAsyncId();\n</code></pre>\n",
"methods": [
{
"textRaw": "asyncResource.runInAsyncScope(fn[, thisArg, ...args])",
"type": "method",
"name": "runInAsyncScope",
"meta": {
"added": [
"v9.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`fn` {Function} The function to call in the execution context of this async resource. ",
"name": "fn",
"type": "Function",
"desc": "The function to call in the execution context of this async resource."
},
{
"textRaw": "`thisArg` {any} The receiver to be used for the function call. ",
"name": "thisArg",
"type": "any",
"desc": "The receiver to be used for the function call.",
"optional": true
},
{
"textRaw": "`...args` {any} Optional arguments to pass to the function. ",
"name": "...args",
"type": "any",
"desc": "Optional arguments to pass to the function.",
"optional": true
}
]
},
{
"params": [
{
"name": "fn"
},
{
"name": "thisArg",
"optional": true
},
{
"name": "...args",
"optional": true
}
]
}
],
"desc": "<p>Call the provided function with the provided arguments in the execution context\nof the async resource. This will establish the context, trigger the AsyncHooks\nbefore callbacks, call the function, trigger the AsyncHooks after callbacks, and\nthen restore the original execution context.</p>\n"
},
{
"textRaw": "asyncResource.emitBefore()",
"type": "method",
"name": "emitBefore",
"meta": {
"deprecated": [
"v9.6.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use [`asyncResource.runInAsyncScope()`][] instead.",
"desc": "<p>Call all <code>before</code> callbacks to notify that a new asynchronous execution context\nis being entered. If nested calls to <code>emitBefore()</code> are made, the stack of\n<code>asyncId</code>s will be tracked and properly unwound.</p>\n<p><code>before</code> and <code>after</code> calls must be unwound in the same order that they\nare called. Otherwise, an unrecoverable exception will occur and the process\nwill abort. For this reason, the <code>emitBefore</code> and <code>emitAfter</code> APIs are\nconsidered deprecated. Please use <code>runInAsyncScope</code>, as it provides a much safer\nalternative.</p>\n",
"signatures": [
{
"params": []
}
]
},
{
"textRaw": "asyncResource.emitAfter()",
"type": "method",
"name": "emitAfter",
"meta": {
"deprecated": [
"v9.6.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use [`asyncResource.runInAsyncScope()`][] instead.",
"desc": "<p>Call all <code>after</code> callbacks. If nested calls to <code>emitBefore()</code> were made, then\nmake sure the stack is unwound properly. Otherwise an error will be thrown.</p>\n<p>If the user&#39;s callback throws an exception, <code>emitAfter()</code> will automatically be\ncalled for all <code>asyncId</code>s on the stack if the error is handled by a domain or\n<code>&#39;uncaughtException&#39;</code> handler.</p>\n<p><code>before</code> and <code>after</code> calls must be unwound in the same order that they\nare called. Otherwise, an unrecoverable exception will occur and the process\nwill abort. For this reason, the <code>emitBefore</code> and <code>emitAfter</code> APIs are\nconsidered deprecated. Please use <code>runInAsyncScope</code>, as it provides a much safer\nalternative.</p>\n",
"signatures": [
{
"params": []
}
]
},
{
"textRaw": "asyncResource.emitDestroy()",
"type": "method",
"name": "emitDestroy",
"desc": "<p>Call all <code>destroy</code> hooks. This should only ever be called once. An error will\nbe thrown if it is called more than once. This <strong>must</strong> be manually called. If\nthe resource is left to be collected by the GC then the <code>destroy</code> hooks will\nnever be called.</p>\n",
"signatures": [
{
"params": []
}
]
},
{
"textRaw": "asyncResource.asyncId()",
"type": "method",
"name": "asyncId",
"signatures": [
{
"return": {
"textRaw": "Returns: {number} The unique `asyncId` assigned to the resource. ",
"name": "return",
"type": "number",
"desc": "The unique `asyncId` assigned to the resource."
},
"params": []
},
{
"params": []
}
]
},
{
"textRaw": "asyncResource.triggerAsyncId()",
"type": "method",
"name": "triggerAsyncId",
"signatures": [
{
"return": {
"textRaw": "Returns: {number} The same `triggerAsyncId` that is passed to the `AsyncResource` constructor. ",
"name": "return",
"type": "number",
"desc": "The same `triggerAsyncId` that is passed to the `AsyncResource` constructor."
},
"params": []
},
{
"params": []
}
]
}
],
"signatures": [
{
"params": [
{
"textRaw": "`type` {string} The type of async event. ",
"name": "type",
"type": "string",
"desc": "The type of async event."
},
{
"textRaw": "`options` {Object} ",
"options": [
{
"textRaw": "`triggerAsyncId` {number} The ID of the execution context that created this async event. **Default:** `executionAsyncId()`. ",
"name": "triggerAsyncId",
"type": "number",
"default": "`executionAsyncId()`",
"desc": "The ID of the execution context that created this async event."
},
{
"textRaw": "`requireManualDestroy` {boolean} Disables automatic `emitDestroy` when the object is garbage collected. This usually does not need to be set (even if `emitDestroy` is called manually), unless the resource's `asyncId` is retrieved and the sensitive API's `emitDestroy` is called with it. **Default:** `false`. ",
"name": "requireManualDestroy",
"type": "boolean",
"default": "`false`",
"desc": "Disables automatic `emitDestroy` when the object is garbage collected. This usually does not need to be set (even if `emitDestroy` is called manually), unless the resource's `asyncId` is retrieved and the sensitive API's `emitDestroy` is called with it."
}
],
"name": "options",
"type": "Object",
"optional": true
}
],
"desc": "<p>Example usage:</p>\n<pre><code class=\"lang-js\">class DBQuery extends AsyncResource {\n constructor(db) {\n super(&#39;DBQuery&#39;);\n this.db = db;\n }\n\n getInfo(query, callback) {\n this.db.get(query, (err, data) =&gt; {\n this.runInAsyncScope(callback, null, err, data);\n });\n }\n\n close() {\n this.db = null;\n this.emitDestroy();\n }\n}\n</code></pre>\n"
},
{
"params": [
{
"name": "type"
},
{
"name": "options",
"optional": true
}
],
"desc": "<p>Example usage:</p>\n<pre><code class=\"lang-js\">class DBQuery extends AsyncResource {\n constructor(db) {\n super(&#39;DBQuery&#39;);\n this.db = db;\n }\n\n getInfo(query, callback) {\n this.db.get(query, (err, data) =&gt; {\n this.runInAsyncScope(callback, null, err, data);\n });\n }\n\n close() {\n this.db = null;\n this.emitDestroy();\n }\n}\n</code></pre>\n"
}
]
}
],
"type": "module",
"displayName": "JavaScript Embedder API"
}
],
"type": "module",
"displayName": "Async Hooks"
},
{
"textRaw": "Buffer",
"name": "buffer",
"introduced_in": "v0.1.90",
"stability": 2,
"stabilityText": "Stable",
"desc": "<p>Prior to the introduction of <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\"><code>TypedArray</code></a>, the JavaScript language had no\nmechanism for reading or manipulating streams of binary data. The <code>Buffer</code> class\nwas introduced as part of the Node.js API to enable interaction with octet\nstreams in TCP streams, file system operations, and other contexts.</p>\n<p>With <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\"><code>TypedArray</code></a> now available, the <code>Buffer</code> class implements the\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array\"><code>Uint8Array</code></a> API in a manner that is more optimized and suitable for Node.js.</p>\n<p>Instances of the <code>Buffer</code> class are similar to arrays of integers but\ncorrespond to fixed-sized, raw memory allocations outside the V8 heap.\nThe size of the <code>Buffer</code> is established when it is created and cannot be\nchanged.</p>\n<p>The <code>Buffer</code> class is within the global scope, making it unlikely that one\nwould need to ever use <code>require(&#39;buffer&#39;).Buffer</code>.</p>\n<pre><code class=\"lang-js\">// Creates a zero-filled Buffer of length 10.\nconst buf1 = Buffer.alloc(10);\n\n// Creates a Buffer of length 10, filled with 0x1.\nconst buf2 = Buffer.alloc(10, 1);\n\n// Creates an uninitialized buffer of length 10.\n// This is faster than calling Buffer.alloc() but the returned\n// Buffer instance might contain old data that needs to be\n// overwritten using either fill() or write().\nconst buf3 = Buffer.allocUnsafe(10);\n\n// Creates a Buffer containing [0x1, 0x2, 0x3].\nconst buf4 = Buffer.from([1, 2, 3]);\n\n// Creates a Buffer containing UTF-8 bytes [0x74, 0xc3, 0xa9, 0x73, 0x74].\nconst buf5 = Buffer.from(&#39;tést&#39;);\n\n// Creates a Buffer containing Latin-1 bytes [0x74, 0xe9, 0x73, 0x74].\nconst buf6 = Buffer.from(&#39;tést&#39;, &#39;latin1&#39;);\n</code></pre>\n",
"modules": [
{
"textRaw": "`Buffer.from()`, `Buffer.alloc()`, and `Buffer.allocUnsafe()`",
"name": "`buffer.from()`,_`buffer.alloc()`,_and_`buffer.allocunsafe()`",
"desc": "<p>In versions of Node.js prior to 6.0.0, <code>Buffer</code> instances were created using the\n<code>Buffer</code> constructor function, which allocates the returned <code>Buffer</code>\ndifferently based on what arguments are provided:</p>\n<ul>\n<li>Passing a number as the first argument to <code>Buffer()</code> (e.g. <code>new Buffer(10)</code>)\nallocates a new <code>Buffer</code> object of the specified size. Prior to Node.js 8.0.0,\nthe memory allocated for such <code>Buffer</code> instances is <em>not</em> initialized and\n<em>can contain sensitive data</em>. Such <code>Buffer</code> instances <em>must</em> be subsequently\ninitialized by using either <a href=\"#buffer_buf_fill_value_offset_end_encoding\"><code>buf.fill(0)</code></a> or by writing to the\nentire <code>Buffer</code>. While this behavior is <em>intentional</em> to improve performance,\ndevelopment experience has demonstrated that a more explicit distinction is\nrequired between creating a fast-but-uninitialized <code>Buffer</code> versus creating a\nslower-but-safer <code>Buffer</code>. Starting in Node.js 8.0.0, <code>Buffer(num)</code> and\n<code>new Buffer(num)</code> will return a <code>Buffer</code> with initialized memory.</li>\n<li>Passing a string, array, or <code>Buffer</code> as the first argument copies the\npassed object&#39;s data into the <code>Buffer</code>.</li>\n<li>Passing an <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer\"><code>ArrayBuffer</code></a> or a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer\"><code>SharedArrayBuffer</code></a> returns a <code>Buffer</code> that\nshares allocated memory with the given array buffer.</li>\n</ul>\n<p>Because the behavior of <code>new Buffer()</code> is different depending on the type of the\nfirst argument, security and reliability issues can be inadvertently introduced\ninto applications when argument validation or <code>Buffer</code> initialization is not\nperformed.</p>\n<p>To make the creation of <code>Buffer</code> instances more reliable and less error-prone,\nthe various forms of the <code>new Buffer()</code> constructor have been <strong>deprecated</strong>\nand replaced by separate <code>Buffer.from()</code>, <a href=\"#buffer_class_method_buffer_alloc_size_fill_encoding\"><code>Buffer.alloc()</code></a>, and\n<a href=\"#buffer_class_method_buffer_allocunsafe_size\"><code>Buffer.allocUnsafe()</code></a> methods.</p>\n<p><em>Developers should migrate all existing uses of the <code>new Buffer()</code> constructors\nto one of these new APIs.</em></p>\n<ul>\n<li><a href=\"#buffer_class_method_buffer_from_array\"><code>Buffer.from(array)</code></a> returns a new <code>Buffer</code> that <em>contains a copy</em> of the\nprovided octets.</li>\n<li><a href=\"#buffer_class_method_buffer_from_arraybuffer_byteoffset_length\"><code>Buffer.from(arrayBuffer[, byteOffset[, length]])</code></a>\nreturns a new <code>Buffer</code> that <em>shares the same allocated memory</em> as the given\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer\"><code>ArrayBuffer</code></a>.</li>\n<li><a href=\"#buffer_class_method_buffer_from_buffer\"><code>Buffer.from(buffer)</code></a> returns a new <code>Buffer</code> that <em>contains a copy</em> of the\ncontents of the given <code>Buffer</code>.</li>\n<li><a href=\"#buffer_class_method_buffer_from_string_encoding\"><code>Buffer.from(string[, encoding])</code></a> returns a new\n<code>Buffer</code> that <em>contains a copy</em> of the provided string.</li>\n<li><a href=\"#buffer_class_method_buffer_alloc_size_fill_encoding\"><code>Buffer.alloc(size[, fill[, encoding]])</code></a> returns a new\ninitialized <code>Buffer</code> of the specified size. This method is slower than\n<a href=\"#buffer_class_method_buffer_allocunsafe_size\"><code>Buffer.allocUnsafe(size)</code></a> but guarantees that newly\ncreated <code>Buffer</code> instances never contain old data that is potentially\nsensitive.</li>\n<li><a href=\"#buffer_class_method_buffer_allocunsafe_size\"><code>Buffer.allocUnsafe(size)</code></a> and\n<a href=\"#buffer_class_method_buffer_allocunsafeslow_size\"><code>Buffer.allocUnsafeSlow(size)</code></a> each return a\nnew uninitialized <code>Buffer</code> of the specified <code>size</code>. Because the <code>Buffer</code> is\nuninitialized, the allocated segment of memory might contain old data that is\npotentially sensitive.</li>\n</ul>\n<p><code>Buffer</code> instances returned by <a href=\"#buffer_class_method_buffer_allocunsafe_size\"><code>Buffer.allocUnsafe()</code></a> <em>may</em> be allocated off\na shared internal memory pool if <code>size</code> is less than or equal to half\n<a href=\"#buffer_class_property_buffer_poolsize\"><code>Buffer.poolSize</code></a>. Instances returned by <a href=\"#buffer_class_method_buffer_allocunsafeslow_size\"><code>Buffer.allocUnsafeSlow()</code></a> <em>never</em>\nuse the shared internal memory pool.</p>\n",
"modules": [
{
"textRaw": "The `--zero-fill-buffers` command line option",
"name": "the_`--zero-fill-buffers`_command_line_option",
"meta": {
"added": [
"v5.10.0"
],
"changes": []
},
"desc": "<p>Node.js can be started using the <code>--zero-fill-buffers</code> command line option to\ncause all newly allocated <code>Buffer</code> instances to be zero-filled upon creation by\ndefault, including buffers returned by <code>new Buffer(size)</code>,\n<a href=\"#buffer_class_method_buffer_allocunsafe_size\"><code>Buffer.allocUnsafe()</code></a>, <a href=\"#buffer_class_method_buffer_allocunsafeslow_size\"><code>Buffer.allocUnsafeSlow()</code></a>, and <code>new\nSlowBuffer(size)</code>. Use of this flag can have a significant negative impact on\nperformance. Use of the <code>--zero-fill-buffers</code> option is recommended only when\nnecessary to enforce that newly allocated <code>Buffer</code> instances cannot contain old\ndata that is potentially sensitive.</p>\n<pre><code class=\"lang-txt\">$ node --zero-fill-buffers\n&gt; Buffer.allocUnsafe(5);\n&lt;Buffer 00 00 00 00 00&gt;\n</code></pre>\n",
"type": "module",
"displayName": "The `--zero-fill-buffers` command line option"
},
{
"textRaw": "What makes `Buffer.allocUnsafe()` and `Buffer.allocUnsafeSlow()` \"unsafe\"?",
"name": "what_makes_`buffer.allocunsafe()`_and_`buffer.allocunsafeslow()`_\"unsafe\"?",
"desc": "<p>When calling <a href=\"#buffer_class_method_buffer_allocunsafe_size\"><code>Buffer.allocUnsafe()</code></a> and <a href=\"#buffer_class_method_buffer_allocunsafeslow_size\"><code>Buffer.allocUnsafeSlow()</code></a>, the\nsegment of allocated memory is <em>uninitialized</em> (it is not zeroed-out). While\nthis design makes the allocation of memory quite fast, the allocated segment of\nmemory might contain old data that is potentially sensitive. Using a <code>Buffer</code>\ncreated by <a href=\"#buffer_class_method_buffer_allocunsafe_size\"><code>Buffer.allocUnsafe()</code></a> without <em>completely</em> overwriting the memory\ncan allow this old data to be leaked when the <code>Buffer</code> memory is read.</p>\n<p>While there are clear performance advantages to using <a href=\"#buffer_class_method_buffer_allocunsafe_size\"><code>Buffer.allocUnsafe()</code></a>,\nextra care <em>must</em> be taken in order to avoid introducing security\nvulnerabilities into an application.</p>\n",
"type": "module",
"displayName": "What makes `Buffer.allocUnsafe()` and `Buffer.allocUnsafeSlow()` \"unsafe\"?"
}
],
"type": "module",
"displayName": "`Buffer.from()`, `Buffer.alloc()`, and `Buffer.allocUnsafe()`"
},
{
"textRaw": "Buffers and Character Encodings",
"name": "buffers_and_character_encodings",
"meta": {
"changes": [
{
"version": "v6.4.0",
"pr-url": "https://github.com/nodejs/node/pull/7111",
"description": "Introduced `latin1` as an alias for `binary`."
},
{
"version": "v5.0.0",
"pr-url": "https://github.com/nodejs/node/pull/2859",
"description": "Removed the deprecated `raw` and `raws` encodings."
}
]
},
"desc": "<p>When string data is stored in or extracted out of a <code>Buffer</code> instance, a\ncharacter encoding may be specified.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from(&#39;hello world&#39;, &#39;ascii&#39;);\n\nconsole.log(buf.toString(&#39;hex&#39;));\n// Prints: 68656c6c6f20776f726c64\nconsole.log(buf.toString(&#39;base64&#39;));\n// Prints: aGVsbG8gd29ybGQ=\n\nconsole.log(Buffer.from(&#39;fhqwhgads&#39;, &#39;ascii&#39;));\n// Prints: &lt;Buffer 66 68 71 77 68 67 61 64 73&gt;\nconsole.log(Buffer.from(&#39;fhqwhgads&#39;, &#39;utf16le&#39;));\n// Prints: &lt;Buffer 66 00 68 00 71 00 77 00 68 00 67 00 61 00 64 00 73 00&gt;\n</code></pre>\n<p>The character encodings currently supported by Node.js include:</p>\n<ul>\n<li><p><code>&#39;ascii&#39;</code> - For 7-bit ASCII data only. This encoding is fast and will strip\nthe high bit if set.</p>\n</li>\n<li><p><code>&#39;utf8&#39;</code> - Multibyte encoded Unicode characters. Many web pages and other\ndocument formats use UTF-8.</p>\n</li>\n<li><p><code>&#39;utf16le&#39;</code> - 2 or 4 bytes, little-endian encoded Unicode characters.\nSurrogate pairs (U+10000 to U+10FFFF) are supported.</p>\n</li>\n<li><p><code>&#39;ucs2&#39;</code> - Alias of <code>&#39;utf16le&#39;</code>.</p>\n</li>\n<li><p><code>&#39;base64&#39;</code> - Base64 encoding. When creating a <code>Buffer</code> from a string,\nthis encoding will also correctly accept &quot;URL and Filename Safe Alphabet&quot; as\nspecified in <a href=\"https://tools.ietf.org/html/rfc4648#section-5\">RFC4648, Section 5</a>.</p>\n</li>\n<li><p><code>&#39;latin1&#39;</code> - A way of encoding the <code>Buffer</code> into a one-byte encoded string\n(as defined by the IANA in <a href=\"https://tools.ietf.org/html/rfc1345\">RFC1345</a>,\npage 63, to be the Latin-1 supplement block and C0/C1 control codes).</p>\n</li>\n<li><p><code>&#39;binary&#39;</code> - Alias for <code>&#39;latin1&#39;</code>.</p>\n</li>\n<li><p><code>&#39;hex&#39;</code> - Encode each byte as two hexadecimal characters.</p>\n</li>\n</ul>\n<p>Modern Web browsers follow the <a href=\"https://encoding.spec.whatwg.org/\">WHATWG Encoding Standard</a> which aliases\nboth <code>&#39;latin1&#39;</code> and <code>&#39;ISO-8859-1&#39;</code> to <code>&#39;win-1252&#39;</code>. This means that while doing\nsomething like <code>http.get()</code>, if the returned charset is one of those listed in\nthe WHATWG specification it is possible that the server actually returned\n<code>&#39;win-1252&#39;</code>-encoded data, and using <code>&#39;latin1&#39;</code> encoding may incorrectly decode\nthe characters.</p>\n",
"type": "module",
"displayName": "Buffers and Character Encodings"
},
{
"textRaw": "Buffers and TypedArray",
"name": "buffers_and_typedarray",
"meta": {
"changes": [
{
"version": "v3.0.0",
"pr-url": "https://github.com/nodejs/node/pull/2002",
"description": "The `Buffer`s class now inherits from `Uint8Array`."
}
]
},
"desc": "<p><code>Buffer</code> instances are also <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array\"><code>Uint8Array</code></a> instances. However, there are subtle\nincompatibilities with <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\"><code>TypedArray</code></a>. For example, while\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice\"><code>ArrayBuffer#slice()</code></a> creates a copy of the slice, the implementation of\n<a href=\"#buffer_buf_slice_start_end\"><code>Buffer#slice()</code></a> creates a view over the existing <code>Buffer</code>\nwithout copying, making <a href=\"#buffer_buf_slice_start_end\"><code>Buffer#slice()</code></a> far more efficient.</p>\n<p>It is also possible to create new <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\"><code>TypedArray</code></a> instances from a <code>Buffer</code> with\nthe following caveats:</p>\n<ol>\n<li><p>The <code>Buffer</code> object&#39;s memory is copied to the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\"><code>TypedArray</code></a>, not shared.</p>\n</li>\n<li><p>The <code>Buffer</code> object&#39;s memory is interpreted as an array of distinct\nelements, and not as a byte array of the target type. That is,\n<code>new Uint32Array(Buffer.from([1, 2, 3, 4]))</code> creates a 4-element <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array\"><code>Uint32Array</code></a>\nwith elements <code>[1, 2, 3, 4]</code>, not a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array\"><code>Uint32Array</code></a> with a single element\n<code>[0x1020304]</code> or <code>[0x4030201]</code>.</p>\n</li>\n</ol>\n<p>It is possible to create a new <code>Buffer</code> that shares the same allocated memory as\na <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\"><code>TypedArray</code></a> instance by using the <code>TypeArray</code> object&#39;s <code>.buffer</code> property.</p>\n<pre><code class=\"lang-js\">const arr = new Uint16Array(2);\n\narr[0] = 5000;\narr[1] = 4000;\n\n// Copies the contents of `arr`\nconst buf1 = Buffer.from(arr);\n// Shares memory with `arr`\nconst buf2 = Buffer.from(arr.buffer);\n\nconsole.log(buf1);\n// Prints: &lt;Buffer 88 a0&gt;\nconsole.log(buf2);\n// Prints: &lt;Buffer 88 13 a0 0f&gt;\n\narr[1] = 6000;\n\nconsole.log(buf1);\n// Prints: &lt;Buffer 88 a0&gt;\nconsole.log(buf2);\n// Prints: &lt;Buffer 88 13 70 17&gt;\n</code></pre>\n<p>Note that when creating a <code>Buffer</code> using a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\"><code>TypedArray</code></a>&#39;s <code>.buffer</code>, it is\npossible to use only a portion of the underlying <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer\"><code>ArrayBuffer</code></a> by passing in\n<code>byteOffset</code> and <code>length</code> parameters.</p>\n<pre><code class=\"lang-js\">const arr = new Uint16Array(20);\nconst buf = Buffer.from(arr.buffer, 0, 16);\n\nconsole.log(buf.length);\n// Prints: 16\n</code></pre>\n<p>The <code>Buffer.from()</code> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from\"><code>TypedArray.from()</code></a> have different signatures and\nimplementations. Specifically, the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\"><code>TypedArray</code></a> variants accept a second\nargument that is a mapping function that is invoked on every element of the\ntyped array:</p>\n<ul>\n<li><code>TypedArray.from(source[, mapFn[, thisArg]])</code></li>\n</ul>\n<p>The <code>Buffer.from()</code> method, however, does not support the use of a mapping\nfunction:</p>\n<ul>\n<li><a href=\"#buffer_class_method_buffer_from_array\"><code>Buffer.from(array)</code></a></li>\n<li><a href=\"#buffer_class_method_buffer_from_buffer\"><code>Buffer.from(buffer)</code></a></li>\n<li><a href=\"#buffer_class_method_buffer_from_arraybuffer_byteoffset_length\"><code>Buffer.from(arrayBuffer[, byteOffset[, length]])</code></a></li>\n<li><a href=\"#buffer_class_method_buffer_from_string_encoding\"><code>Buffer.from(string[, encoding])</code></a></li>\n</ul>\n",
"type": "module",
"displayName": "Buffers and TypedArray"
},
{
"textRaw": "Buffers and iteration",
"name": "buffers_and_iteration",
"desc": "<p><code>Buffer</code> instances can be iterated over using <code>for..of</code> syntax:</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([1, 2, 3]);\n\n// Prints:\n// 1\n// 2\n// 3\nfor (const b of buf) {\n console.log(b);\n}\n</code></pre>\n<p>Additionally, the <a href=\"#buffer_buf_values\"><code>buf.values()</code></a>, <a href=\"#buffer_buf_keys\"><code>buf.keys()</code></a>, and\n<a href=\"#buffer_buf_entries\"><code>buf.entries()</code></a> methods can be used to create iterators.</p>\n",
"type": "module",
"displayName": "Buffers and iteration"
},
{
"textRaw": "Buffer Constants",
"name": "buffer_constants",
"meta": {
"added": [
"v8.2.0"
],
"changes": []
},
"desc": "<p>Note that <code>buffer.constants</code> is a property on the <code>buffer</code> module returned by\n<code>require(&#39;buffer&#39;)</code>, not on the <code>Buffer</code> global or a <code>Buffer</code> instance.</p>\n",
"properties": [
{
"textRaw": "`MAX_LENGTH` {integer} The largest size allowed for a single `Buffer` instance. ",
"type": "integer",
"name": "MAX_LENGTH",
"meta": {
"added": [
"v8.2.0"
],
"changes": []
},
"desc": "<p>On 32-bit architectures, this value is <code>(2^30)-1</code> (~1GB).\nOn 64-bit architectures, this value is <code>(2^31)-1</code> (~2GB).</p>\n<p>This value is also available as <a href=\"#buffer_buffer_kmaxlength\"><code>buffer.kMaxLength</code></a>.</p>\n",
"shortDesc": "The largest size allowed for a single `Buffer` instance."
},
{
"textRaw": "`MAX_STRING_LENGTH` {integer} The largest length allowed for a single `string` instance. ",
"type": "integer",
"name": "MAX_STRING_LENGTH",
"meta": {
"added": [
"v8.2.0"
],
"changes": []
},
"desc": "<p>Represents the largest <code>length</code> that a <code>string</code> primitive can have, counted\nin UTF-16 code units.</p>\n<p>This value may depend on the JS engine that is being used.</p>\n",
"shortDesc": "The largest length allowed for a single `string` instance."
}
],
"type": "module",
"displayName": "Buffer Constants"
}
],
"classes": [
{
"textRaw": "Class: Buffer",
"type": "class",
"name": "Buffer",
"desc": "<p>The <code>Buffer</code> class is a global type for dealing with binary data directly.\nIt can be constructed in a variety of ways.</p>\n",
"classMethods": [
{
"textRaw": "Class Method: Buffer.alloc(size[, fill[, encoding]])",
"type": "classMethod",
"name": "alloc",
"meta": {
"added": [
"v5.10.0"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18129",
"description": "Attempting to fill a non-zero length buffer with a zero length buffer triggers a thrown exception."
},
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/17427",
"description": "Specifying an invalid string for `fill` triggers a thrown exception."
},
{
"version": "v8.9.3",
"pr-url": "https://github.com/nodejs/node/pull/17428",
"description": "Specifying an invalid string for `fill` now results in a zero-filled buffer."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`size` {integer} The desired length of the new `Buffer`. ",
"name": "size",
"type": "integer",
"desc": "The desired length of the new `Buffer`."
},
{
"textRaw": "`fill` {string|Buffer|integer} A value to pre-fill the new `Buffer` with. **Default:** `0`. ",
"name": "fill",
"type": "string|Buffer|integer",
"default": "`0`",
"desc": "A value to pre-fill the new `Buffer` with.",
"optional": true
},
{
"textRaw": "`encoding` {string} If `fill` is a string, this is its encoding. **Default:** `'utf8'`. ",
"name": "encoding",
"type": "string",
"default": "`'utf8'`",
"desc": "If `fill` is a string, this is its encoding.",
"optional": true
}
]
},
{
"params": [
{
"name": "size"
},
{
"name": "fill",
"optional": true
},
{
"name": "encoding",
"optional": true
}
]
}
],
"desc": "<p>Allocates a new <code>Buffer</code> of <code>size</code> bytes. If <code>fill</code> is <code>undefined</code>, the\n<code>Buffer</code> will be <em>zero-filled</em>.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.alloc(5);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 00 00 00 00 00&gt;\n</code></pre>\n<p>Allocates a new <code>Buffer</code> of <code>size</code> bytes. If <code>size</code> is larger than\n<a href=\"#buffer_buffer_constants_max_length\"><code>buffer.constants.MAX_LENGTH</code></a> or smaller than 0, <a href=\"errors.html#ERR_INVALID_OPT_VALUE\"><code>ERR_INVALID_OPT_VALUE</code></a> is\nthrown. A zero-length <code>Buffer</code> is created if <code>size</code> is 0.</p>\n<p>If <code>fill</code> is specified, the allocated <code>Buffer</code> will be initialized by calling\n<a href=\"#buffer_buf_fill_value_offset_end_encoding\"><code>buf.fill(fill)</code></a>.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.alloc(5, &#39;a&#39;);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 61 61 61 61 61&gt;\n</code></pre>\n<p>If both <code>fill</code> and <code>encoding</code> are specified, the allocated <code>Buffer</code> will be\ninitialized by calling <a href=\"#buffer_buf_fill_value_offset_end_encoding\"><code>buf.fill(fill, encoding)</code></a>.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.alloc(11, &#39;aGVsbG8gd29ybGQ=&#39;, &#39;base64&#39;);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64&gt;\n</code></pre>\n<p>Calling <a href=\"#buffer_class_method_buffer_alloc_size_fill_encoding\"><code>Buffer.alloc()</code></a> can be significantly slower than the alternative\n<a href=\"#buffer_class_method_buffer_allocunsafe_size\"><code>Buffer.allocUnsafe()</code></a> but ensures that the newly created <code>Buffer</code> instance\ncontents will <em>never contain sensitive data</em>.</p>\n<p>A <code>TypeError</code> will be thrown if <code>size</code> is not a number.</p>\n"
},
{
"textRaw": "Class Method: Buffer.allocUnsafe(size)",
"type": "classMethod",
"name": "allocUnsafe",
"meta": {
"added": [
"v5.10.0"
],
"changes": [
{
"version": "v7.0.0",
"pr-url": "https://github.com/nodejs/node/pull/7079",
"description": "Passing a negative `size` will now throw an error."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`size` {integer} The desired length of the new `Buffer`. ",
"name": "size",
"type": "integer",
"desc": "The desired length of the new `Buffer`."
}
]
},
{
"params": [
{
"name": "size"
}
]
}
],
"desc": "<p>Allocates a new <code>Buffer</code> of <code>size</code> bytes. If <code>size</code> is larger than\n<a href=\"#buffer_buffer_constants_max_length\"><code>buffer.constants.MAX_LENGTH</code></a> or smaller than 0, <a href=\"errors.html#ERR_INVALID_OPT_VALUE\"><code>ERR_INVALID_OPT_VALUE</code></a> is\nthrown. A zero-length <code>Buffer</code> is created if <code>size</code> is 0.</p>\n<p>The underlying memory for <code>Buffer</code> instances created in this way is <em>not\ninitialized</em>. The contents of the newly created <code>Buffer</code> are unknown and\n<em>may contain sensitive data</em>. Use <a href=\"#buffer_class_method_buffer_alloc_size_fill_encoding\"><code>Buffer.alloc()</code></a> instead to initialize\n<code>Buffer</code> instances with zeroes.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(10);\n\nconsole.log(buf);\n// Prints: (contents may vary): &lt;Buffer a0 8b 28 3f 01 00 00 00 50 32&gt;\n\nbuf.fill(0);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 00 00 00 00 00 00 00 00 00 00&gt;\n</code></pre>\n<p>A <code>TypeError</code> will be thrown if <code>size</code> is not a number.</p>\n<p>Note that the <code>Buffer</code> module pre-allocates an internal <code>Buffer</code> instance of\nsize <a href=\"#buffer_class_property_buffer_poolsize\"><code>Buffer.poolSize</code></a> that is used as a pool for the fast allocation of new\n<code>Buffer</code> instances created using <a href=\"#buffer_class_method_buffer_allocunsafe_size\"><code>Buffer.allocUnsafe()</code></a> and the deprecated\n<code>new Buffer(size)</code> constructor only when <code>size</code> is less than or equal to\n<code>Buffer.poolSize &gt;&gt; 1</code> (floor of <a href=\"#buffer_class_property_buffer_poolsize\"><code>Buffer.poolSize</code></a> divided by two).</p>\n<p>Use of this pre-allocated internal memory pool is a key difference between\ncalling <code>Buffer.alloc(size, fill)</code> vs. <code>Buffer.allocUnsafe(size).fill(fill)</code>.\nSpecifically, <code>Buffer.alloc(size, fill)</code> will <em>never</em> use the internal <code>Buffer</code>\npool, while <code>Buffer.allocUnsafe(size).fill(fill)</code> <em>will</em> use the internal\n<code>Buffer</code> pool if <code>size</code> is less than or equal to half <a href=\"#buffer_class_property_buffer_poolsize\"><code>Buffer.poolSize</code></a>. The\ndifference is subtle but can be important when an application requires the\nadditional performance that <a href=\"#buffer_class_method_buffer_allocunsafe_size\"><code>Buffer.allocUnsafe()</code></a> provides.</p>\n"
},
{
"textRaw": "Class Method: Buffer.allocUnsafeSlow(size)",
"type": "classMethod",
"name": "allocUnsafeSlow",
"meta": {
"added": [
"v5.12.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`size` {integer} The desired length of the new `Buffer`. ",
"name": "size",
"type": "integer",
"desc": "The desired length of the new `Buffer`."
}
]
},
{
"params": [
{
"name": "size"
}
]
}
],
"desc": "<p>Allocates a new <code>Buffer</code> of <code>size</code> bytes. If <code>size</code> is larger than\n<a href=\"#buffer_buffer_constants_max_length\"><code>buffer.constants.MAX_LENGTH</code></a> or smaller than 0, <a href=\"errors.html#ERR_INVALID_OPT_VALUE\"><code>ERR_INVALID_OPT_VALUE</code></a> is\nthrown. A zero-length <code>Buffer</code> is created if <code>size</code> is 0.</p>\n<p>The underlying memory for <code>Buffer</code> instances created in this way is <em>not\ninitialized</em>. The contents of the newly created <code>Buffer</code> are unknown and\n<em>may contain sensitive data</em>. Use <a href=\"#buffer_buf_fill_value_offset_end_encoding\"><code>buf.fill(0)</code></a> to initialize\nsuch <code>Buffer</code> instances with zeroes.</p>\n<p>When using <a href=\"#buffer_class_method_buffer_allocunsafe_size\"><code>Buffer.allocUnsafe()</code></a> to allocate new <code>Buffer</code> instances,\nallocations under 4KB are sliced from a single pre-allocated <code>Buffer</code>. This\nallows applications to avoid the garbage collection overhead of creating many\nindividually allocated <code>Buffer</code> instances. This approach improves both\nperformance and memory usage by eliminating the need to track and clean up as\nmany persistent objects.</p>\n<p>However, in the case where a developer may need to retain a small chunk of\nmemory from a pool for an indeterminate amount of time, it may be appropriate\nto create an un-pooled <code>Buffer</code> instance using <code>Buffer.allocUnsafeSlow()</code> and\nthen copying out the relevant bits.</p>\n<pre><code class=\"lang-js\">// Need to keep around a few small chunks of memory\nconst store = [];\n\nsocket.on(&#39;readable&#39;, () =&gt; {\n const data = socket.read();\n\n // Allocate for retained data\n const sb = Buffer.allocUnsafeSlow(10);\n\n // Copy the data into the new allocation\n data.copy(sb, 0, 0, 10);\n\n store.push(sb);\n});\n</code></pre>\n<p><code>Buffer.allocUnsafeSlow()</code> should be used only as a last resort after a\ndeveloper has observed undue memory retention in their applications.</p>\n<p>A <code>TypeError</code> will be thrown if <code>size</code> is not a number.</p>\n"
},
{
"textRaw": "Class Method: Buffer.byteLength(string[, encoding])",
"type": "classMethod",
"name": "byteLength",
"meta": {
"added": [
"v0.1.90"
],
"changes": [
{
"version": "v7.0.0",
"pr-url": "https://github.com/nodejs/node/pull/8946",
"description": "Passing invalid input will now throw an error."
},
{
"version": "v5.10.0",
"pr-url": "https://github.com/nodejs/node/pull/5255",
"description": "The `string` parameter can now be any `TypedArray`, `DataView` or `ArrayBuffer`."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} The number of bytes contained within `string`. ",
"name": "return",
"type": "integer",
"desc": "The number of bytes contained within `string`."
},
"params": [
{
"textRaw": "`string` {string|Buffer|TypedArray|DataView|ArrayBuffer|SharedArrayBuffer} A value to calculate the length of. ",
"name": "string",
"type": "string|Buffer|TypedArray|DataView|ArrayBuffer|SharedArrayBuffer",
"desc": "A value to calculate the length of."
},
{
"textRaw": "`encoding` {string} If `string` is a string, this is its encoding. **Default:** `'utf8'`. ",
"name": "encoding",
"type": "string",
"default": "`'utf8'`",
"desc": "If `string` is a string, this is its encoding.",
"optional": true
}
]
},
{
"params": [
{
"name": "string"
},
{
"name": "encoding",
"optional": true
}
]
}
],
"desc": "<p>Returns the actual byte length of a string. This is not the same as\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length\"><code>String.prototype.length</code></a> since that returns the number of <em>characters</em> in\na string.</p>\n<p>For <code>&#39;base64&#39;</code> and <code>&#39;hex&#39;</code>, this function assumes valid input. For strings that\ncontain non-Base64/Hex-encoded data (e.g. whitespace), the return value might be\ngreater than the length of a <code>Buffer</code> created from the string.</p>\n<pre><code class=\"lang-js\">const str = &#39;\\u00bd + \\u00bc = \\u00be&#39;;\n\nconsole.log(`${str}: ${str.length} characters, ` +\n `${Buffer.byteLength(str, &#39;utf8&#39;)} bytes`);\n// Prints: ½ + ¼ = ¾: 9 characters, 12 bytes\n</code></pre>\n<p>When <code>string</code> is a <code>Buffer</code>/<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView\"><code>DataView</code></a>/<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\"><code>TypedArray</code></a>/<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer\"><code>ArrayBuffer</code></a>/\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer\"><code>SharedArrayBuffer</code></a>, the actual byte length is returned.</p>\n"
},
{
"textRaw": "Class Method: Buffer.compare(buf1, buf2)",
"type": "classMethod",
"name": "compare",
"meta": {
"added": [
"v0.11.13"
],
"changes": [
{
"version": "v8.0.0",
"pr-url": "https://github.com/nodejs/node/pull/10236",
"description": "The arguments can now be `Uint8Array`s."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} ",
"name": "return",
"type": "integer"
},
"params": [
{
"textRaw": "`buf1` {Buffer|Uint8Array} ",
"name": "buf1",
"type": "Buffer|Uint8Array"
},
{
"textRaw": "`buf2` {Buffer|Uint8Array} ",
"name": "buf2",
"type": "Buffer|Uint8Array"
}
]
},
{
"params": [
{
"name": "buf1"
},
{
"name": "buf2"
}
]
}
],
"desc": "<p>Compares <code>buf1</code> to <code>buf2</code> typically for the purpose of sorting arrays of\n<code>Buffer</code> instances. This is equivalent to calling\n<a href=\"#buffer_buf_compare_target_targetstart_targetend_sourcestart_sourceend\"><code>buf1.compare(buf2)</code></a>.</p>\n<pre><code class=\"lang-js\">const buf1 = Buffer.from(&#39;1234&#39;);\nconst buf2 = Buffer.from(&#39;0123&#39;);\nconst arr = [buf1, buf2];\n\nconsole.log(arr.sort(Buffer.compare));\n// Prints: [ &lt;Buffer 30 31 32 33&gt;, &lt;Buffer 31 32 33 34&gt; ]\n// (This result is equal to: [buf2, buf1])\n</code></pre>\n"
},
{
"textRaw": "Class Method: Buffer.concat(list[, totalLength])",
"type": "classMethod",
"name": "concat",
"meta": {
"added": [
"v0.7.11"
],
"changes": [
{
"version": "v8.0.0",
"pr-url": "https://github.com/nodejs/node/pull/10236",
"description": "The elements of `list` can now be `Uint8Array`s."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Buffer} ",
"name": "return",
"type": "Buffer"
},
"params": [
{
"textRaw": "`list` {Buffer[] | Uint8Array[]} List of `Buffer` or [`Uint8Array`] instances to concat. ",
"name": "list",
"type": "Buffer[] | Uint8Array[]",
"desc": "List of `Buffer` or [`Uint8Array`] instances to concat."
},
{
"textRaw": "`totalLength` {integer} Total length of the `Buffer` instances in `list` when concatenated. ",
"name": "totalLength",
"type": "integer",
"desc": "Total length of the `Buffer` instances in `list` when concatenated.",
"optional": true
}
]
},
{
"params": [
{
"name": "list"
},
{
"name": "totalLength",
"optional": true
}
]
}
],
"desc": "<p>Returns a new <code>Buffer</code> which is the result of concatenating all the <code>Buffer</code>\ninstances in the <code>list</code> together.</p>\n<p>If the list has no items, or if the <code>totalLength</code> is 0, then a new zero-length\n<code>Buffer</code> is returned.</p>\n<p>If <code>totalLength</code> is not provided, it is calculated from the <code>Buffer</code> instances\nin <code>list</code>. This however causes an additional loop to be executed in order to\ncalculate the <code>totalLength</code>, so it is faster to provide the length explicitly if\nit is already known.</p>\n<p>If <code>totalLength</code> is provided, it is coerced to an unsigned integer. If the\ncombined length of the <code>Buffer</code>s in <code>list</code> exceeds <code>totalLength</code>, the result is\ntruncated to <code>totalLength</code>.</p>\n<pre><code class=\"lang-js\">// Create a single `Buffer` from a list of three `Buffer` instances.\n\nconst buf1 = Buffer.alloc(10);\nconst buf2 = Buffer.alloc(14);\nconst buf3 = Buffer.alloc(18);\nconst totalLength = buf1.length + buf2.length + buf3.length;\n\nconsole.log(totalLength);\n// Prints: 42\n\nconst bufA = Buffer.concat([buf1, buf2, buf3], totalLength);\n\nconsole.log(bufA);\n// Prints: &lt;Buffer 00 00 00 00 ...&gt;\nconsole.log(bufA.length);\n// Prints: 42\n</code></pre>\n"
},
{
"textRaw": "Class Method: Buffer.from(array)",
"type": "classMethod",
"name": "from",
"meta": {
"added": [
"v5.10.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`array` {integer[]} ",
"name": "array",
"type": "integer[]"
}
]
},
{
"params": [
{
"name": "array"
}
]
}
],
"desc": "<p>Allocates a new <code>Buffer</code> using an <code>array</code> of octets.</p>\n<pre><code class=\"lang-js\">// Creates a new Buffer containing UTF-8 bytes of the string &#39;buffer&#39;\nconst buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);\n</code></pre>\n<p>A <code>TypeError</code> will be thrown if <code>array</code> is not an <code>Array</code>.</p>\n"
},
{
"textRaw": "Class Method: Buffer.from(arrayBuffer[, byteOffset[, length]])",
"type": "classMethod",
"name": "from",
"meta": {
"added": [
"v5.10.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An [`ArrayBuffer`], [`SharedArrayBuffer`], or the `.buffer` property of a [`TypedArray`]. ",
"name": "arrayBuffer",
"type": "ArrayBuffer|SharedArrayBuffer",
"desc": "An [`ArrayBuffer`], [`SharedArrayBuffer`], or the `.buffer` property of a [`TypedArray`]."
},
{
"textRaw": "`byteOffset` {integer} Index of first byte to expose. **Default:** `0`. ",
"name": "byteOffset",
"type": "integer",
"default": "`0`",
"desc": "Index of first byte to expose.",
"optional": true
},
{
"textRaw": "`length` {integer} Number of bytes to expose. **Default:** `arrayBuffer.length - byteOffset`. ",
"name": "length",
"type": "integer",
"default": "`arrayBuffer.length - byteOffset`",
"desc": "Number of bytes to expose.",
"optional": true
}
]
},
{
"params": [
{
"name": "arrayBuffer"
},
{
"name": "byteOffset",
"optional": true
},
{
"name": "length",
"optional": true
}
]
}
],
"desc": "<p>This creates a view of the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer\"><code>ArrayBuffer</code></a> without copying the underlying\nmemory. For example, when passed a reference to the <code>.buffer</code> property of a\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\"><code>TypedArray</code></a> instance, the newly created <code>Buffer</code> will share the same\nallocated memory as the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\"><code>TypedArray</code></a>.</p>\n<pre><code class=\"lang-js\">const arr = new Uint16Array(2);\n\narr[0] = 5000;\narr[1] = 4000;\n\n// Shares memory with `arr`\nconst buf = Buffer.from(arr.buffer);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 88 13 a0 0f&gt;\n\n// Changing the original Uint16Array changes the Buffer also\narr[1] = 6000;\n\nconsole.log(buf);\n// Prints: &lt;Buffer 88 13 70 17&gt;\n</code></pre>\n<p>The optional <code>byteOffset</code> and <code>length</code> arguments specify a memory range within\nthe <code>arrayBuffer</code> that will be shared by the <code>Buffer</code>.</p>\n<pre><code class=\"lang-js\">const ab = new ArrayBuffer(10);\nconst buf = Buffer.from(ab, 0, 2);\n\nconsole.log(buf.length);\n// Prints: 2\n</code></pre>\n<p>A <code>TypeError</code> will be thrown if <code>arrayBuffer</code> is not an <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer\"><code>ArrayBuffer</code></a> or a\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer\"><code>SharedArrayBuffer</code></a>.</p>\n"
},
{
"textRaw": "Class Method: Buffer.from(buffer)",
"type": "classMethod",
"name": "from",
"meta": {
"added": [
"v5.10.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`buffer` {Buffer|Uint8Array} An existing `Buffer` or [`Uint8Array`] from which to copy data. ",
"name": "buffer",
"type": "Buffer|Uint8Array",
"desc": "An existing `Buffer` or [`Uint8Array`] from which to copy data."
}
]
},
{
"params": [
{
"name": "buffer"
}
]
}
],
"desc": "<p>Copies the passed <code>buffer</code> data onto a new <code>Buffer</code> instance.</p>\n<pre><code class=\"lang-js\">const buf1 = Buffer.from(&#39;buffer&#39;);\nconst buf2 = Buffer.from(buf1);\n\nbuf1[0] = 0x61;\n\nconsole.log(buf1.toString());\n// Prints: auffer\nconsole.log(buf2.toString());\n// Prints: buffer\n</code></pre>\n<p>A <code>TypeError</code> will be thrown if <code>buffer</code> is not a <code>Buffer</code>.</p>\n"
},
{
"textRaw": "Class Method: Buffer.from(string[, encoding])",
"type": "classMethod",
"name": "from",
"meta": {
"added": [
"v5.10.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`string` {string} A string to encode. ",
"name": "string",
"type": "string",
"desc": "A string to encode."
},
{
"textRaw": "`encoding` {string} The encoding of `string`. **Default:** `'utf8'`. ",
"name": "encoding",
"type": "string",
"default": "`'utf8'`",
"desc": "The encoding of `string`.",
"optional": true
}
]
},
{
"params": [
{
"name": "string"
},
{
"name": "encoding",
"optional": true
}
]
}
],
"desc": "<p>Creates a new <code>Buffer</code> containing <code>string</code>. The <code>encoding</code> parameter identifies\nthe character encoding of <code>string</code>.</p>\n<pre><code class=\"lang-js\">const buf1 = Buffer.from(&#39;this is a tést&#39;);\nconst buf2 = Buffer.from(&#39;7468697320697320612074c3a97374&#39;, &#39;hex&#39;);\n\nconsole.log(buf1.toString());\n// Prints: this is a tést\nconsole.log(buf2.toString());\n// Prints: this is a tést\nconsole.log(buf1.toString(&#39;ascii&#39;));\n// Prints: this is a tC)st\n</code></pre>\n<p>A <code>TypeError</code> will be thrown if <code>string</code> is not a string.</p>\n"
},
{
"textRaw": "Class Method: Buffer.from(object[, offsetOrEncoding[, length]])",
"type": "classMethod",
"name": "from",
"meta": {
"added": [
"v8.2.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`object` {Object} An object supporting `Symbol.toPrimitive` or `valueOf()` ",
"name": "object",
"type": "Object",
"desc": "An object supporting `Symbol.toPrimitive` or `valueOf()`"
},
{
"textRaw": "`offsetOrEncoding` {number|string} A byte-offset or encoding, depending on the value returned either by `object.valueOf()` or `object[Symbol.toPrimitive]()`. ",
"name": "offsetOrEncoding",
"type": "number|string",
"desc": "A byte-offset or encoding, depending on the value returned either by `object.valueOf()` or `object[Symbol.toPrimitive]()`.",
"optional": true
},
{
"textRaw": "`length` {number} A length, depending on the value returned either by `object.valueOf()` or `object[Symbol.toPrimitive]()`. ",
"name": "length",
"type": "number",
"desc": "A length, depending on the value returned either by `object.valueOf()` or `object[Symbol.toPrimitive]()`.",
"optional": true
}
]
},
{
"params": [
{
"name": "object"
},
{
"name": "offsetOrEncoding",
"optional": true
},
{
"name": "length",
"optional": true
}
]
}
],
"desc": "<p>For objects whose <code>valueOf()</code> function returns a value not strictly equal to\n<code>object</code>, returns <code>Buffer.from(object.valueOf(), offsetOrEncoding, length)</code>.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from(new String(&#39;this is a test&#39;));\n// Prints: &lt;Buffer 74 68 69 73 20 69 73 20 61 20 74 65 73 74&gt;\n</code></pre>\n<p>For objects that support <code>Symbol.toPrimitive</code>, returns\n<code>Buffer.from(object[Symbol.toPrimitive](), offsetOrEncoding, length)</code>.</p>\n<pre><code class=\"lang-js\">class Foo {\n [Symbol.toPrimitive]() {\n return &#39;this is a test&#39;;\n }\n}\n\nconst buf = Buffer.from(new Foo(), &#39;utf8&#39;);\n// Prints: &lt;Buffer 74 68 69 73 20 69 73 20 61 20 74 65 73 74&gt;\n</code></pre>\n"
},
{
"textRaw": "Class Method: Buffer.isBuffer(obj)",
"type": "classMethod",
"name": "isBuffer",
"meta": {
"added": [
"v0.1.101"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean} ",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`obj` {Object} ",
"name": "obj",
"type": "Object"
}
]
},
{
"params": [
{
"name": "obj"
}
]
}
],
"desc": "<p>Returns <code>true</code> if <code>obj</code> is a <code>Buffer</code>, <code>false</code> otherwise.</p>\n"
},
{
"textRaw": "Class Method: Buffer.isEncoding(encoding)",
"type": "classMethod",
"name": "isEncoding",
"meta": {
"added": [
"v0.9.1"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean} ",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`encoding` {string} A character encoding name to check. ",
"name": "encoding",
"type": "string",
"desc": "A character encoding name to check."
}
]
},
{
"params": [
{
"name": "encoding"
}
]
}
],
"desc": "<p>Returns <code>true</code> if <code>encoding</code> contains a supported character encoding, or <code>false</code>\notherwise.</p>\n"
}
],
"properties": [
{
"textRaw": "`poolSize` {integer} **Default:** `8192` ",
"type": "integer",
"name": "poolSize",
"meta": {
"added": [
"v0.11.3"
],
"changes": []
},
"default": "`8192`",
"desc": "<p>This is the size (in bytes) of pre-allocated internal <code>Buffer</code> instances used\nfor pooling. This value may be modified.</p>\n"
},
{
"textRaw": "buf[index]",
"name": "[index]",
"meta": {
"type": "property",
"name": [
"index"
],
"changes": []
},
"desc": "<p>The index operator <code>[index]</code> can be used to get and set the octet at position\n<code>index</code> in <code>buf</code>. The values refer to individual bytes, so the legal value\nrange is between <code>0x00</code> and <code>0xFF</code> (hex) or <code>0</code> and <code>255</code> (decimal).</p>\n<p>This operator is inherited from <code>Uint8Array</code>, so its behavior on out-of-bounds\naccess is the same as <code>UInt8Array</code> - that is, getting returns <code>undefined</code> and\nsetting does nothing.</p>\n<pre><code class=\"lang-js\">// Copy an ASCII string into a `Buffer` one byte at a time.\n\nconst str = &#39;Node.js&#39;;\nconst buf = Buffer.allocUnsafe(str.length);\n\nfor (let i = 0; i &lt; str.length; i++) {\n buf[i] = str.charCodeAt(i);\n}\n\nconsole.log(buf.toString(&#39;ascii&#39;));\n// Prints: Node.js\n</code></pre>\n"
},
{
"textRaw": "`buffer` {ArrayBuffer} The underlying `ArrayBuffer` object based on which this `Buffer` object is created. ",
"type": "ArrayBuffer",
"name": "buffer",
"desc": "<pre><code class=\"lang-js\">const arrayBuffer = new ArrayBuffer(16);\nconst buffer = Buffer.from(arrayBuffer);\n\nconsole.log(buffer.buffer === arrayBuffer);\n// Prints: true\n</code></pre>\n",
"shortDesc": "The underlying `ArrayBuffer` object based on which this `Buffer` object is created."
},
{
"textRaw": "`length` {integer} ",
"type": "integer",
"name": "length",
"meta": {
"added": [
"v0.1.90"
],
"changes": []
},
"desc": "<p>Returns the amount of memory allocated for <code>buf</code> in bytes. Note that this\ndoes not necessarily reflect the amount of &quot;usable&quot; data within <code>buf</code>.</p>\n<pre><code class=\"lang-js\">// Create a `Buffer` and write a shorter ASCII string to it.\n\nconst buf = Buffer.alloc(1234);\n\nconsole.log(buf.length);\n// Prints: 1234\n\nbuf.write(&#39;some string&#39;, 0, &#39;ascii&#39;);\n\nconsole.log(buf.length);\n// Prints: 1234\n</code></pre>\n<p>While the <code>length</code> property is not immutable, changing the value of <code>length</code>\ncan result in undefined and inconsistent behavior. Applications that wish to\nmodify the length of a <code>Buffer</code> should therefore treat <code>length</code> as read-only and\nuse <a href=\"#buffer_buf_slice_start_end\"><code>buf.slice()</code></a> to create a new <code>Buffer</code>.</p>\n<pre><code class=\"lang-js\">let buf = Buffer.allocUnsafe(10);\n\nbuf.write(&#39;abcdefghj&#39;, 0, &#39;ascii&#39;);\n\nconsole.log(buf.length);\n// Prints: 10\n\nbuf = buf.slice(0, 5);\n\nconsole.log(buf.length);\n// Prints: 5\n</code></pre>\n"
},
{
"textRaw": "buf.parent",
"name": "parent",
"meta": {
"deprecated": [
"v8.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use [`buf.buffer`] instead.",
"desc": "<p>The <code>buf.parent</code> property is a deprecated alias for <code>buf.buffer</code>.</p>\n"
}
],
"methods": [
{
"textRaw": "buf.compare(target[, targetStart[, targetEnd[, sourceStart[, sourceEnd]]]])",
"type": "method",
"name": "compare",
"meta": {
"added": [
"v0.11.13"
],
"changes": [
{
"version": "v8.0.0",
"pr-url": "https://github.com/nodejs/node/pull/10236",
"description": "The `target` parameter can now be a `Uint8Array`."
},
{
"version": "v5.11.0",
"pr-url": "https://github.com/nodejs/node/pull/5880",
"description": "Additional parameters for specifying offsets are supported now."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} ",
"name": "return",
"type": "integer"
},
"params": [
{
"textRaw": "`target` {Buffer|Uint8Array} A `Buffer` or [`Uint8Array`] with which to compare `buf`. ",
"name": "target",
"type": "Buffer|Uint8Array",
"desc": "A `Buffer` or [`Uint8Array`] with which to compare `buf`."
},
{
"textRaw": "`targetStart` {integer} The offset within `target` at which to begin comparison. **Default:** `0`. ",
"name": "targetStart",
"type": "integer",
"default": "`0`",
"desc": "The offset within `target` at which to begin comparison.",
"optional": true
},
{
"textRaw": "`targetEnd` {integer} The offset with `target` at which to end comparison (not inclusive). **Default:** `target.length`. ",
"name": "targetEnd",
"type": "integer",
"default": "`target.length`",
"desc": "The offset with `target` at which to end comparison (not inclusive).",
"optional": true
},
{
"textRaw": "`sourceStart` {integer} The offset within `buf` at which to begin comparison. **Default:** `0`. ",
"name": "sourceStart",
"type": "integer",
"default": "`0`",
"desc": "The offset within `buf` at which to begin comparison.",
"optional": true
},
{
"textRaw": "`sourceEnd` {integer} The offset within `buf` at which to end comparison (not inclusive). **Default:** [`buf.length`]. ",
"name": "sourceEnd",
"type": "integer",
"default": "[`buf.length`]",
"desc": "The offset within `buf` at which to end comparison (not inclusive).",
"optional": true
}
]
},
{
"params": [
{
"name": "target"
},
{
"name": "targetStart",
"optional": true
},
{
"name": "targetEnd",
"optional": true
},
{
"name": "sourceStart",
"optional": true
},
{
"name": "sourceEnd",
"optional": true
}
]
}
],
"desc": "<p>Compares <code>buf</code> with <code>target</code> and returns a number indicating whether <code>buf</code>\ncomes before, after, or is the same as <code>target</code> in sort order.\nComparison is based on the actual sequence of bytes in each <code>Buffer</code>.</p>\n<ul>\n<li><code>0</code> is returned if <code>target</code> is the same as <code>buf</code></li>\n<li><code>1</code> is returned if <code>target</code> should come <em>before</em> <code>buf</code> when sorted.</li>\n<li><code>-1</code> is returned if <code>target</code> should come <em>after</em> <code>buf</code> when sorted.</li>\n</ul>\n<pre><code class=\"lang-js\">const buf1 = Buffer.from(&#39;ABC&#39;);\nconst buf2 = Buffer.from(&#39;BCD&#39;);\nconst buf3 = Buffer.from(&#39;ABCD&#39;);\n\nconsole.log(buf1.compare(buf1));\n// Prints: 0\nconsole.log(buf1.compare(buf2));\n// Prints: -1\nconsole.log(buf1.compare(buf3));\n// Prints: -1\nconsole.log(buf2.compare(buf1));\n// Prints: 1\nconsole.log(buf2.compare(buf3));\n// Prints: 1\nconsole.log([buf1, buf2, buf3].sort(Buffer.compare));\n// Prints: [ &lt;Buffer 41 42 43&gt;, &lt;Buffer 41 42 43 44&gt;, &lt;Buffer 42 43 44&gt; ]\n// (This result is equal to: [buf1, buf3, buf2])\n</code></pre>\n<p>The optional <code>targetStart</code>, <code>targetEnd</code>, <code>sourceStart</code>, and <code>sourceEnd</code>\narguments can be used to limit the comparison to specific ranges within <code>target</code>\nand <code>buf</code> respectively.</p>\n<pre><code class=\"lang-js\">const buf1 = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9]);\nconst buf2 = Buffer.from([5, 6, 7, 8, 9, 1, 2, 3, 4]);\n\nconsole.log(buf1.compare(buf2, 5, 9, 0, 4));\n// Prints: 0\nconsole.log(buf1.compare(buf2, 0, 6, 4));\n// Prints: -1\nconsole.log(buf1.compare(buf2, 5, 6, 5));\n// Prints: 1\n</code></pre>\n<p><a href=\"errors.html#ERR_INDEX_OUT_OF_RANGE\"><code>ERR_INDEX_OUT_OF_RANGE</code></a> is thrown if <code>targetStart &lt; 0</code>, <code>sourceStart &lt; 0</code>,\n<code>targetEnd &gt; target.byteLength</code>, or <code>sourceEnd &gt; source.byteLength</code>.</p>\n"
},
{
"textRaw": "buf.copy(target[, targetStart[, sourceStart[, sourceEnd]]])",
"type": "method",
"name": "copy",
"meta": {
"added": [
"v0.1.90"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} The number of bytes copied. ",
"name": "return",
"type": "integer",
"desc": "The number of bytes copied."
},
"params": [
{
"textRaw": "`target` {Buffer|Uint8Array} A `Buffer` or [`Uint8Array`] to copy into. ",
"name": "target",
"type": "Buffer|Uint8Array",
"desc": "A `Buffer` or [`Uint8Array`] to copy into."
},
{
"textRaw": "`targetStart` {integer} The offset within `target` at which to begin writing. **Default:** `0`. ",
"name": "targetStart",
"type": "integer",
"default": "`0`",
"desc": "The offset within `target` at which to begin writing.",
"optional": true
},
{
"textRaw": "`sourceStart` {integer} The offset within `buf` from which to begin copying. **Default:** `0`. ",
"name": "sourceStart",
"type": "integer",
"default": "`0`",
"desc": "The offset within `buf` from which to begin copying.",
"optional": true
},
{
"textRaw": "`sourceEnd` {integer} The offset within `buf` at which to stop copying (not inclusive). **Default:** [`buf.length`]. ",
"name": "sourceEnd",
"type": "integer",
"default": "[`buf.length`]",
"desc": "The offset within `buf` at which to stop copying (not inclusive).",
"optional": true
}
]
},
{
"params": [
{
"name": "target"
},
{
"name": "targetStart",
"optional": true
},
{
"name": "sourceStart",
"optional": true
},
{
"name": "sourceEnd",
"optional": true
}
]
}
],
"desc": "<p>Copies data from a region of <code>buf</code> to a region in <code>target</code> even if the <code>target</code>\nmemory region overlaps with <code>buf</code>.</p>\n<pre><code class=\"lang-js\">// Create two `Buffer` instances.\nconst buf1 = Buffer.allocUnsafe(26);\nconst buf2 = Buffer.allocUnsafe(26).fill(&#39;!&#39;);\n\nfor (let i = 0; i &lt; 26; i++) {\n // 97 is the decimal ASCII value for &#39;a&#39;\n buf1[i] = i + 97;\n}\n\n// Copy `buf1` bytes 16 through 19 into `buf2` starting at byte 8 of `buf2`\nbuf1.copy(buf2, 8, 16, 20);\n\nconsole.log(buf2.toString(&#39;ascii&#39;, 0, 25));\n// Prints: !!!!!!!!qrst!!!!!!!!!!!!!\n</code></pre>\n<pre><code class=\"lang-js\">// Create a `Buffer` and copy data from one region to an overlapping region\n// within the same `Buffer`.\n\nconst buf = Buffer.allocUnsafe(26);\n\nfor (let i = 0; i &lt; 26; i++) {\n // 97 is the decimal ASCII value for &#39;a&#39;\n buf[i] = i + 97;\n}\n\nbuf.copy(buf, 0, 4, 10);\n\nconsole.log(buf.toString());\n// Prints: efghijghijklmnopqrstuvwxyz\n</code></pre>\n"
},
{
"textRaw": "buf.entries()",
"type": "method",
"name": "entries",
"meta": {
"added": [
"v1.1.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Iterator} ",
"name": "return",
"type": "Iterator"
},
"params": []
},
{
"params": []
}
],
"desc": "<p>Creates and returns an <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols\">iterator</a> of <code>[index, byte]</code> pairs from the contents of\n<code>buf</code>.</p>\n<pre><code class=\"lang-js\">// Log the entire contents of a `Buffer`.\n\nconst buf = Buffer.from(&#39;buffer&#39;);\n\nfor (const pair of buf.entries()) {\n console.log(pair);\n}\n// Prints:\n// [0, 98]\n// [1, 117]\n// [2, 102]\n// [3, 102]\n// [4, 101]\n// [5, 114]\n</code></pre>\n"
},
{
"textRaw": "buf.equals(otherBuffer)",
"type": "method",
"name": "equals",
"meta": {
"added": [
"v0.11.13"
],
"changes": [
{
"version": "v8.0.0",
"pr-url": "https://github.com/nodejs/node/pull/10236",
"description": "The arguments can now be `Uint8Array`s."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean} ",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`otherBuffer` {Buffer} A `Buffer` or [`Uint8Array`] with which to compare `buf`. ",
"name": "otherBuffer",
"type": "Buffer",
"desc": "A `Buffer` or [`Uint8Array`] with which to compare `buf`."
}
]
},
{
"params": [
{
"name": "otherBuffer"
}
]
}
],
"desc": "<p>Returns <code>true</code> if both <code>buf</code> and <code>otherBuffer</code> have exactly the same bytes,\n<code>false</code> otherwise.</p>\n<pre><code class=\"lang-js\">const buf1 = Buffer.from(&#39;ABC&#39;);\nconst buf2 = Buffer.from(&#39;414243&#39;, &#39;hex&#39;);\nconst buf3 = Buffer.from(&#39;ABCD&#39;);\n\nconsole.log(buf1.equals(buf2));\n// Prints: true\nconsole.log(buf1.equals(buf3));\n// Prints: false\n</code></pre>\n"
},
{
"textRaw": "buf.fill(value[, offset[, end]][, encoding])",
"type": "method",
"name": "fill",
"meta": {
"added": [
"v0.5.0"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18790",
"description": "Negative `end` values throw an `ERR_INDEX_OUT_OF_RANGE` error."
},
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18129",
"description": "Attempting to fill a non-zero length buffer with a zero length buffer triggers a thrown exception."
},
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/17427",
"description": "Specifying an invalid string for `value` triggers a thrown exception."
},
{
"version": "v5.7.0",
"pr-url": "https://github.com/nodejs/node/pull/4935",
"description": "The `encoding` parameter is supported now."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Buffer} A reference to `buf`. ",
"name": "return",
"type": "Buffer",
"desc": "A reference to `buf`."
},
"params": [
{
"textRaw": "`value` {string|Buffer|integer} The value with which to fill `buf`. ",
"name": "value",
"type": "string|Buffer|integer",
"desc": "The value with which to fill `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to fill `buf`. **Default:** `0`. ",
"name": "offset",
"type": "integer",
"default": "`0`",
"desc": "Number of bytes to skip before starting to fill `buf`.",
"optional": true
},
{
"textRaw": "`end` {integer} Where to stop filling `buf` (not inclusive). **Default:** [`buf.length`]. ",
"name": "end",
"type": "integer",
"default": "[`buf.length`]",
"desc": "Where to stop filling `buf` (not inclusive).",
"optional": true
},
{
"textRaw": "`encoding` {string} The encoding for `value` if `value` is a string. **Default:** `'utf8'`. ",
"name": "encoding",
"type": "string",
"default": "`'utf8'`",
"desc": "The encoding for `value` if `value` is a string.",
"optional": true
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset",
"optional": true
},
{
"name": "end",
"optional": true
},
{
"name": "encoding",
"optional": true
}
]
}
],
"desc": "<p>Fills <code>buf</code> with the specified <code>value</code>. If the <code>offset</code> and <code>end</code> are not given,\nthe entire <code>buf</code> will be filled:</p>\n<pre><code class=\"lang-js\">// Fill a `Buffer` with the ASCII character &#39;h&#39;.\n\nconst b = Buffer.allocUnsafe(50).fill(&#39;h&#39;);\n\nconsole.log(b.toString());\n// Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n</code></pre>\n<p><code>value</code> is coerced to a <code>uint32</code> value if it is not a string or integer.</p>\n<p>If the final write of a <code>fill()</code> operation falls on a multi-byte character,\nthen only the bytes of that character that fit into <code>buf</code> are written:</p>\n<pre><code class=\"lang-js\">// Fill a `Buffer` with a two-byte character.\n\nconsole.log(Buffer.allocUnsafe(3).fill(&#39;\\u0222&#39;));\n// Prints: &lt;Buffer c8 a2 c8&gt;\n</code></pre>\n<p>If <code>value</code> contains invalid characters, it is truncated; if no valid\nfill data remains, an exception is thrown:</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(5);\n\nconsole.log(buf.fill(&#39;a&#39;));\n// Prints: &lt;Buffer 61 61 61 61 61&gt;\nconsole.log(buf.fill(&#39;aazz&#39;, &#39;hex&#39;));\n// Prints: &lt;Buffer aa aa aa aa aa&gt;\nconsole.log(buf.fill(&#39;zz&#39;, &#39;hex&#39;));\n// Throws an exception.\n</code></pre>\n"
},
{
"textRaw": "buf.includes(value[, byteOffset][, encoding])",
"type": "method",
"name": "includes",
"meta": {
"added": [
"v5.3.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean} `true` if `value` was found in `buf`, `false` otherwise. ",
"name": "return",
"type": "boolean",
"desc": "`true` if `value` was found in `buf`, `false` otherwise."
},
"params": [
{
"textRaw": "`value` {string|Buffer|integer} What to search for. ",
"name": "value",
"type": "string|Buffer|integer",
"desc": "What to search for."
},
{
"textRaw": "`byteOffset` {integer} Where to begin searching in `buf`. **Default:** `0`. ",
"name": "byteOffset",
"type": "integer",
"default": "`0`",
"desc": "Where to begin searching in `buf`.",
"optional": true
},
{
"textRaw": "`encoding` {string} If `value` is a string, this is its encoding. **Default:** `'utf8'`. ",
"name": "encoding",
"type": "string",
"default": "`'utf8'`",
"desc": "If `value` is a string, this is its encoding.",
"optional": true
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "byteOffset",
"optional": true
},
{
"name": "encoding",
"optional": true
}
]
}
],
"desc": "<p>Equivalent to <a href=\"#buffer_buf_indexof_value_byteoffset_encoding\"><code>buf.indexOf() !== -1</code></a>.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from(&#39;this is a buffer&#39;);\n\nconsole.log(buf.includes(&#39;this&#39;));\n// Prints: true\nconsole.log(buf.includes(&#39;is&#39;));\n// Prints: true\nconsole.log(buf.includes(Buffer.from(&#39;a buffer&#39;)));\n// Prints: true\nconsole.log(buf.includes(97));\n// Prints: true (97 is the decimal ASCII value for &#39;a&#39;)\nconsole.log(buf.includes(Buffer.from(&#39;a buffer example&#39;)));\n// Prints: false\nconsole.log(buf.includes(Buffer.from(&#39;a buffer example&#39;).slice(0, 8)));\n// Prints: true\nconsole.log(buf.includes(&#39;this&#39;, 4));\n// Prints: false\n</code></pre>\n"
},
{
"textRaw": "buf.indexOf(value[, byteOffset][, encoding])",
"type": "method",
"name": "indexOf",
"meta": {
"added": [
"v1.5.0"
],
"changes": [
{
"version": "v8.0.0",
"pr-url": "https://github.com/nodejs/node/pull/10236",
"description": "The `value` can now be a `Uint8Array`."
},
{
"version": "v5.7.0, v4.4.0",
"pr-url": "https://github.com/nodejs/node/pull/4803",
"description": "When `encoding` is being passed, the `byteOffset` parameter is no longer required."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} The index of the first occurrence of `value` in `buf`, or `-1` if `buf` does not contain `value`. ",
"name": "return",
"type": "integer",
"desc": "The index of the first occurrence of `value` in `buf`, or `-1` if `buf` does not contain `value`."
},
"params": [
{
"textRaw": "`value` {string|Buffer|Uint8Array|integer} What to search for. ",
"name": "value",
"type": "string|Buffer|Uint8Array|integer",
"desc": "What to search for."
},
{
"textRaw": "`byteOffset` {integer} Where to begin searching in `buf`. **Default:** `0`. ",
"name": "byteOffset",
"type": "integer",
"default": "`0`",
"desc": "Where to begin searching in `buf`.",
"optional": true
},
{
"textRaw": "`encoding` {string} If `value` is a string, this is the encoding used to determine the binary representation of the string that will be searched for in `buf`. **Default:** `'utf8'`. ",
"name": "encoding",
"type": "string",
"default": "`'utf8'`",
"desc": "If `value` is a string, this is the encoding used to determine the binary representation of the string that will be searched for in `buf`.",
"optional": true
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "byteOffset",
"optional": true
},
{
"name": "encoding",
"optional": true
}
]
}
],
"desc": "<p>If <code>value</code> is:</p>\n<ul>\n<li>a string, <code>value</code> is interpreted according to the character encoding in\n<code>encoding</code>.</li>\n<li>a <code>Buffer</code> or <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array\"><code>Uint8Array</code></a>, <code>value</code> will be used in its entirety.\nTo compare a partial <code>Buffer</code>, use <a href=\"#buffer_buf_slice_start_end\"><code>buf.slice()</code></a>.</li>\n<li>a number, <code>value</code> will be interpreted as an unsigned 8-bit integer\nvalue between <code>0</code> and <code>255</code>.</li>\n</ul>\n<pre><code class=\"lang-js\">const buf = Buffer.from(&#39;this is a buffer&#39;);\n\nconsole.log(buf.indexOf(&#39;this&#39;));\n// Prints: 0\nconsole.log(buf.indexOf(&#39;is&#39;));\n// Prints: 2\nconsole.log(buf.indexOf(Buffer.from(&#39;a buffer&#39;)));\n// Prints: 8\nconsole.log(buf.indexOf(97));\n// Prints: 8 (97 is the decimal ASCII value for &#39;a&#39;)\nconsole.log(buf.indexOf(Buffer.from(&#39;a buffer example&#39;)));\n// Prints: -1\nconsole.log(buf.indexOf(Buffer.from(&#39;a buffer example&#39;).slice(0, 8)));\n// Prints: 8\n\nconst utf16Buffer = Buffer.from(&#39;\\u039a\\u0391\\u03a3\\u03a3\\u0395&#39;, &#39;utf16le&#39;);\n\nconsole.log(utf16Buffer.indexOf(&#39;\\u03a3&#39;, 0, &#39;utf16le&#39;));\n// Prints: 4\nconsole.log(utf16Buffer.indexOf(&#39;\\u03a3&#39;, -4, &#39;utf16le&#39;));\n// Prints: 6\n</code></pre>\n<p>If <code>value</code> is not a string, number, or <code>Buffer</code>, this method will throw a\n<code>TypeError</code>. If <code>value</code> is a number, it will be coerced to a valid byte value,\nan integer between 0 and 255.</p>\n<p>If <code>byteOffset</code> is not a number, it will be coerced to a number. If the result\nof coercion is <code>NaN</code> or <code>0</code>, then the entire buffer will be searched. This\nbehavior matches <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf\"><code>String#indexOf()</code></a>.</p>\n<pre><code class=\"lang-js\">const b = Buffer.from(&#39;abcdef&#39;);\n\n// Passing a value that&#39;s a number, but not a valid byte\n// Prints: 2, equivalent to searching for 99 or &#39;c&#39;\nconsole.log(b.indexOf(99.9));\nconsole.log(b.indexOf(256 + 99));\n\n// Passing a byteOffset that coerces to NaN or 0\n// Prints: 1, searching the whole buffer\nconsole.log(b.indexOf(&#39;b&#39;, undefined));\nconsole.log(b.indexOf(&#39;b&#39;, {}));\nconsole.log(b.indexOf(&#39;b&#39;, null));\nconsole.log(b.indexOf(&#39;b&#39;, []));\n</code></pre>\n<p>If <code>value</code> is an empty string or empty <code>Buffer</code> and <code>byteOffset</code> is less\nthan <code>buf.length</code>, <code>byteOffset</code> will be returned. If <code>value</code> is empty and\n<code>byteOffset</code> is at least <code>buf.length</code>, <code>buf.length</code> will be returned.</p>\n"
},
{
"textRaw": "buf.keys()",
"type": "method",
"name": "keys",
"meta": {
"added": [
"v1.1.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Iterator} ",
"name": "return",
"type": "Iterator"
},
"params": []
},
{
"params": []
}
],
"desc": "<p>Creates and returns an <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols\">iterator</a> of <code>buf</code> keys (indices).</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from(&#39;buffer&#39;);\n\nfor (const key of buf.keys()) {\n console.log(key);\n}\n// Prints:\n// 0\n// 1\n// 2\n// 3\n// 4\n// 5\n</code></pre>\n"
},
{
"textRaw": "buf.lastIndexOf(value[, byteOffset][, encoding])",
"type": "method",
"name": "lastIndexOf",
"meta": {
"added": [
"v6.0.0"
],
"changes": [
{
"version": "v8.0.0",
"pr-url": "https://github.com/nodejs/node/pull/10236",
"description": "The `value` can now be a `Uint8Array`."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} The index of the last occurrence of `value` in `buf`, or `-1` if `buf` does not contain `value`. ",
"name": "return",
"type": "integer",
"desc": "The index of the last occurrence of `value` in `buf`, or `-1` if `buf` does not contain `value`."
},
"params": [
{
"textRaw": "`value` {string|Buffer|Uint8Array|integer} What to search for. ",
"name": "value",
"type": "string|Buffer|Uint8Array|integer",
"desc": "What to search for."
},
{
"textRaw": "`byteOffset` {integer} Where to begin searching in `buf`. **Default:** [`buf.length`]` - 1`. ",
"name": "byteOffset",
"type": "integer",
"default": "[`buf.length`]` - 1`",
"desc": "Where to begin searching in `buf`.",
"optional": true
},
{
"textRaw": "`encoding` {string} If `value` is a string, this is the encoding used to determine the binary representation of the string that will be searched for in `buf`. **Default:** `'utf8'`. ",
"name": "encoding",
"type": "string",
"default": "`'utf8'`",
"desc": "If `value` is a string, this is the encoding used to determine the binary representation of the string that will be searched for in `buf`.",
"optional": true
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "byteOffset",
"optional": true
},
{
"name": "encoding",
"optional": true
}
]
}
],
"desc": "<p>Identical to <a href=\"#buffer_buf_indexof_value_byteoffset_encoding\"><code>buf.indexOf()</code></a>, except the last occurrence of <code>value</code> is found\nrather than the first occurrence.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from(&#39;this buffer is a buffer&#39;);\n\nconsole.log(buf.lastIndexOf(&#39;this&#39;));\n// Prints: 0\nconsole.log(buf.lastIndexOf(&#39;buffer&#39;));\n// Prints: 17\nconsole.log(buf.lastIndexOf(Buffer.from(&#39;buffer&#39;)));\n// Prints: 17\nconsole.log(buf.lastIndexOf(97));\n// Prints: 15 (97 is the decimal ASCII value for &#39;a&#39;)\nconsole.log(buf.lastIndexOf(Buffer.from(&#39;yolo&#39;)));\n// Prints: -1\nconsole.log(buf.lastIndexOf(&#39;buffer&#39;, 5));\n// Prints: 5\nconsole.log(buf.lastIndexOf(&#39;buffer&#39;, 4));\n// Prints: -1\n\nconst utf16Buffer = Buffer.from(&#39;\\u039a\\u0391\\u03a3\\u03a3\\u0395&#39;, &#39;utf16le&#39;);\n\nconsole.log(utf16Buffer.lastIndexOf(&#39;\\u03a3&#39;, undefined, &#39;utf16le&#39;));\n// Prints: 6\nconsole.log(utf16Buffer.lastIndexOf(&#39;\\u03a3&#39;, -5, &#39;utf16le&#39;));\n// Prints: 4\n</code></pre>\n<p>If <code>value</code> is not a string, number, or <code>Buffer</code>, this method will throw a\n<code>TypeError</code>. If <code>value</code> is a number, it will be coerced to a valid byte value,\nan integer between 0 and 255.</p>\n<p>If <code>byteOffset</code> is not a number, it will be coerced to a number. Any arguments\nthat coerce to <code>NaN</code>, like <code>{}</code> or <code>undefined</code>, will search the whole buffer.\nThis behavior matches <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf\"><code>String#lastIndexOf()</code></a>.</p>\n<pre><code class=\"lang-js\">const b = Buffer.from(&#39;abcdef&#39;);\n\n// Passing a value that&#39;s a number, but not a valid byte\n// Prints: 2, equivalent to searching for 99 or &#39;c&#39;\nconsole.log(b.lastIndexOf(99.9));\nconsole.log(b.lastIndexOf(256 + 99));\n\n// Passing a byteOffset that coerces to NaN\n// Prints: 1, searching the whole buffer\nconsole.log(b.lastIndexOf(&#39;b&#39;, undefined));\nconsole.log(b.lastIndexOf(&#39;b&#39;, {}));\n\n// Passing a byteOffset that coerces to 0\n// Prints: -1, equivalent to passing 0\nconsole.log(b.lastIndexOf(&#39;b&#39;, null));\nconsole.log(b.lastIndexOf(&#39;b&#39;, []));\n</code></pre>\n<p>If <code>value</code> is an empty string or empty <code>Buffer</code>, <code>byteOffset</code> will be returned.</p>\n"
},
{
"textRaw": "buf.readDoubleBE(offset)",
"type": "method",
"name": "readDoubleBE",
"meta": {
"added": [
"v0.11.15"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {number} ",
"name": "return",
"type": "number"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 8`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 8`."
}
]
},
{
"params": [
{
"name": "offset"
}
]
},
{
"params": [
{
"name": "offset"
}
]
}
],
"desc": "<p>Reads a 64-bit double from <code>buf</code> at the specified <code>offset</code> with specified\nendian format (<code>readDoubleBE()</code> returns big endian, <code>readDoubleLE()</code> returns\nlittle endian).</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);\n\nconsole.log(buf.readDoubleBE(0));\n// Prints: 8.20788039913184e-304\nconsole.log(buf.readDoubleLE(0));\n// Prints: 5.447603722011605e-270\nconsole.log(buf.readDoubleLE(1));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readDoubleLE(offset)",
"type": "method",
"name": "readDoubleLE",
"meta": {
"added": [
"v0.11.15"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {number} ",
"name": "return",
"type": "number"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 8`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 8`."
}
]
},
{
"params": [
{
"name": "offset"
}
]
}
],
"desc": "<p>Reads a 64-bit double from <code>buf</code> at the specified <code>offset</code> with specified\nendian format (<code>readDoubleBE()</code> returns big endian, <code>readDoubleLE()</code> returns\nlittle endian).</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);\n\nconsole.log(buf.readDoubleBE(0));\n// Prints: 8.20788039913184e-304\nconsole.log(buf.readDoubleLE(0));\n// Prints: 5.447603722011605e-270\nconsole.log(buf.readDoubleLE(1));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readFloatBE(offset)",
"type": "method",
"name": "readFloatBE",
"meta": {
"added": [
"v0.11.15"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {number} ",
"name": "return",
"type": "number"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`."
}
]
},
{
"params": [
{
"name": "offset"
}
]
},
{
"params": [
{
"name": "offset"
}
]
}
],
"desc": "<p>Reads a 32-bit float from <code>buf</code> at the specified <code>offset</code> with specified\nendian format (<code>readFloatBE()</code> returns big endian, <code>readFloatLE()</code> returns\nlittle endian).</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([1, 2, 3, 4]);\n\nconsole.log(buf.readFloatBE(0));\n// Prints: 2.387939260590663e-38\nconsole.log(buf.readFloatLE(0));\n// Prints: 1.539989614439558e-36\nconsole.log(buf.readFloatLE(1));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readFloatLE(offset)",
"type": "method",
"name": "readFloatLE",
"meta": {
"added": [
"v0.11.15"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {number} ",
"name": "return",
"type": "number"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`."
}
]
},
{
"params": [
{
"name": "offset"
}
]
}
],
"desc": "<p>Reads a 32-bit float from <code>buf</code> at the specified <code>offset</code> with specified\nendian format (<code>readFloatBE()</code> returns big endian, <code>readFloatLE()</code> returns\nlittle endian).</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([1, 2, 3, 4]);\n\nconsole.log(buf.readFloatBE(0));\n// Prints: 2.387939260590663e-38\nconsole.log(buf.readFloatLE(0));\n// Prints: 1.539989614439558e-36\nconsole.log(buf.readFloatLE(1));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readInt8(offset)",
"type": "method",
"name": "readInt8",
"meta": {
"added": [
"v0.5.0"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} ",
"name": "return",
"type": "integer"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 1`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 1`."
}
]
},
{
"params": [
{
"name": "offset"
}
]
}
],
"desc": "<p>Reads a signed 8-bit integer from <code>buf</code> at the specified <code>offset</code>.</p>\n<p>Integers read from a <code>Buffer</code> are interpreted as two&#39;s complement signed values.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([-1, 5]);\n\nconsole.log(buf.readInt8(0));\n// Prints: -1\nconsole.log(buf.readInt8(1));\n// Prints: 5\nconsole.log(buf.readInt8(2));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readInt16BE(offset)",
"type": "method",
"name": "readInt16BE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} ",
"name": "return",
"type": "integer"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`."
}
]
},
{
"params": [
{
"name": "offset"
}
]
},
{
"params": [
{
"name": "offset"
}
]
}
],
"desc": "<p>Reads a signed 16-bit integer from <code>buf</code> at the specified <code>offset</code> with\nthe specified endian format (<code>readInt16BE()</code> returns big endian,\n<code>readInt16LE()</code> returns little endian).</p>\n<p>Integers read from a <code>Buffer</code> are interpreted as two&#39;s complement signed values.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([0, 5]);\n\nconsole.log(buf.readInt16BE(0));\n// Prints: 5\nconsole.log(buf.readInt16LE(0));\n// Prints: 1280\nconsole.log(buf.readInt16LE(1));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readInt16LE(offset)",
"type": "method",
"name": "readInt16LE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} ",
"name": "return",
"type": "integer"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`."
}
]
},
{
"params": [
{
"name": "offset"
}
]
}
],
"desc": "<p>Reads a signed 16-bit integer from <code>buf</code> at the specified <code>offset</code> with\nthe specified endian format (<code>readInt16BE()</code> returns big endian,\n<code>readInt16LE()</code> returns little endian).</p>\n<p>Integers read from a <code>Buffer</code> are interpreted as two&#39;s complement signed values.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([0, 5]);\n\nconsole.log(buf.readInt16BE(0));\n// Prints: 5\nconsole.log(buf.readInt16LE(0));\n// Prints: 1280\nconsole.log(buf.readInt16LE(1));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readInt32BE(offset)",
"type": "method",
"name": "readInt32BE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} ",
"name": "return",
"type": "integer"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`."
}
]
},
{
"params": [
{
"name": "offset"
}
]
},
{
"params": [
{
"name": "offset"
}
]
}
],
"desc": "<p>Reads a signed 32-bit integer from <code>buf</code> at the specified <code>offset</code> with\nthe specified endian format (<code>readInt32BE()</code> returns big endian,\n<code>readInt32LE()</code> returns little endian).</p>\n<p>Integers read from a <code>Buffer</code> are interpreted as two&#39;s complement signed values.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([0, 0, 0, 5]);\n\nconsole.log(buf.readInt32BE(0));\n// Prints: 5\nconsole.log(buf.readInt32LE(0));\n// Prints: 83886080\nconsole.log(buf.readInt32LE(1));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readInt32LE(offset)",
"type": "method",
"name": "readInt32LE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} ",
"name": "return",
"type": "integer"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`."
}
]
},
{
"params": [
{
"name": "offset"
}
]
}
],
"desc": "<p>Reads a signed 32-bit integer from <code>buf</code> at the specified <code>offset</code> with\nthe specified endian format (<code>readInt32BE()</code> returns big endian,\n<code>readInt32LE()</code> returns little endian).</p>\n<p>Integers read from a <code>Buffer</code> are interpreted as two&#39;s complement signed values.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([0, 0, 0, 5]);\n\nconsole.log(buf.readInt32BE(0));\n// Prints: 5\nconsole.log(buf.readInt32LE(0));\n// Prints: 83886080\nconsole.log(buf.readInt32LE(1));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readIntBE(offset, byteLength)",
"type": "method",
"name": "readIntBE",
"meta": {
"added": [
"v0.11.15"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset and `byteLength` to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} ",
"name": "return",
"type": "integer"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`."
},
{
"textRaw": "`byteLength` {integer} Number of bytes to read. Must satisfy `0 < byteLength <= 6`. ",
"name": "byteLength",
"type": "integer",
"desc": "Number of bytes to read. Must satisfy `0 < byteLength <= 6`."
}
]
},
{
"params": [
{
"name": "offset"
},
{
"name": "byteLength"
}
]
},
{
"params": [
{
"name": "offset"
},
{
"name": "byteLength"
}
]
}
],
"desc": "<p>Reads <code>byteLength</code> number of bytes from <code>buf</code> at the specified <code>offset</code>\nand interprets the result as a two&#39;s complement signed value. Supports up to 48\nbits of accuracy.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);\n\nconsole.log(buf.readIntLE(0, 6).toString(16));\n// Prints: -546f87a9cbee\nconsole.log(buf.readIntBE(0, 6).toString(16));\n// Prints: 1234567890ab\nconsole.log(buf.readIntBE(1, 6).toString(16));\n// Throws ERR_INDEX_OUT_OF_RANGE\nconsole.log(buf.readIntBE(1, 0).toString(16));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readIntLE(offset, byteLength)",
"type": "method",
"name": "readIntLE",
"meta": {
"added": [
"v0.11.15"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset and `byteLength` to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} ",
"name": "return",
"type": "integer"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`."
},
{
"textRaw": "`byteLength` {integer} Number of bytes to read. Must satisfy `0 < byteLength <= 6`. ",
"name": "byteLength",
"type": "integer",
"desc": "Number of bytes to read. Must satisfy `0 < byteLength <= 6`."
}
]
},
{
"params": [
{
"name": "offset"
},
{
"name": "byteLength"
}
]
}
],
"desc": "<p>Reads <code>byteLength</code> number of bytes from <code>buf</code> at the specified <code>offset</code>\nand interprets the result as a two&#39;s complement signed value. Supports up to 48\nbits of accuracy.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);\n\nconsole.log(buf.readIntLE(0, 6).toString(16));\n// Prints: -546f87a9cbee\nconsole.log(buf.readIntBE(0, 6).toString(16));\n// Prints: 1234567890ab\nconsole.log(buf.readIntBE(1, 6).toString(16));\n// Throws ERR_INDEX_OUT_OF_RANGE\nconsole.log(buf.readIntBE(1, 0).toString(16));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readUInt8(offset)",
"type": "method",
"name": "readUInt8",
"meta": {
"added": [
"v0.5.0"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} ",
"name": "return",
"type": "integer"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 1`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 1`."
}
]
},
{
"params": [
{
"name": "offset"
}
]
}
],
"desc": "<p>Reads an unsigned 8-bit integer from <code>buf</code> at the specified <code>offset</code>.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([1, -2]);\n\nconsole.log(buf.readUInt8(0));\n// Prints: 1\nconsole.log(buf.readUInt8(1));\n// Prints: 254\nconsole.log(buf.readUInt8(2));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readUInt16BE(offset)",
"type": "method",
"name": "readUInt16BE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} ",
"name": "return",
"type": "integer"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`."
}
]
},
{
"params": [
{
"name": "offset"
}
]
},
{
"params": [
{
"name": "offset"
}
]
}
],
"desc": "<p>Reads an unsigned 16-bit integer from <code>buf</code> at the specified <code>offset</code> with\nspecified endian format (<code>readUInt16BE()</code> returns big endian, <code>readUInt16LE()</code>\nreturns little endian).</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([0x12, 0x34, 0x56]);\n\nconsole.log(buf.readUInt16BE(0).toString(16));\n// Prints: 1234\nconsole.log(buf.readUInt16LE(0).toString(16));\n// Prints: 3412\nconsole.log(buf.readUInt16BE(1).toString(16));\n// Prints: 3456\nconsole.log(buf.readUInt16LE(1).toString(16));\n// Prints: 5634\nconsole.log(buf.readUInt16LE(2).toString(16));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readUInt16LE(offset)",
"type": "method",
"name": "readUInt16LE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} ",
"name": "return",
"type": "integer"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`."
}
]
},
{
"params": [
{
"name": "offset"
}
]
}
],
"desc": "<p>Reads an unsigned 16-bit integer from <code>buf</code> at the specified <code>offset</code> with\nspecified endian format (<code>readUInt16BE()</code> returns big endian, <code>readUInt16LE()</code>\nreturns little endian).</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([0x12, 0x34, 0x56]);\n\nconsole.log(buf.readUInt16BE(0).toString(16));\n// Prints: 1234\nconsole.log(buf.readUInt16LE(0).toString(16));\n// Prints: 3412\nconsole.log(buf.readUInt16BE(1).toString(16));\n// Prints: 3456\nconsole.log(buf.readUInt16LE(1).toString(16));\n// Prints: 5634\nconsole.log(buf.readUInt16LE(2).toString(16));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readUInt32BE(offset)",
"type": "method",
"name": "readUInt32BE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} ",
"name": "return",
"type": "integer"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`."
}
]
},
{
"params": [
{
"name": "offset"
}
]
},
{
"params": [
{
"name": "offset"
}
]
}
],
"desc": "<p>Reads an unsigned 32-bit integer from <code>buf</code> at the specified <code>offset</code> with\nspecified endian format (<code>readUInt32BE()</code> returns big endian,\n<code>readUInt32LE()</code> returns little endian).</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);\n\nconsole.log(buf.readUInt32BE(0).toString(16));\n// Prints: 12345678\nconsole.log(buf.readUInt32LE(0).toString(16));\n// Prints: 78563412\nconsole.log(buf.readUInt32LE(1).toString(16));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readUInt32LE(offset)",
"type": "method",
"name": "readUInt32LE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} ",
"name": "return",
"type": "integer"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`."
}
]
},
{
"params": [
{
"name": "offset"
}
]
}
],
"desc": "<p>Reads an unsigned 32-bit integer from <code>buf</code> at the specified <code>offset</code> with\nspecified endian format (<code>readUInt32BE()</code> returns big endian,\n<code>readUInt32LE()</code> returns little endian).</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);\n\nconsole.log(buf.readUInt32BE(0).toString(16));\n// Prints: 12345678\nconsole.log(buf.readUInt32LE(0).toString(16));\n// Prints: 78563412\nconsole.log(buf.readUInt32LE(1).toString(16));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readUIntBE(offset, byteLength)",
"type": "method",
"name": "readUIntBE",
"meta": {
"added": [
"v0.11.15"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset and `byteLength` to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} ",
"name": "return",
"type": "integer"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`."
},
{
"textRaw": "`byteLength` {integer} Number of bytes to read. Must satisfy `0 < byteLength <= 6`. ",
"name": "byteLength",
"type": "integer",
"desc": "Number of bytes to read. Must satisfy `0 < byteLength <= 6`."
}
]
},
{
"params": [
{
"name": "offset"
},
{
"name": "byteLength"
}
]
},
{
"params": [
{
"name": "offset"
},
{
"name": "byteLength"
}
]
}
],
"desc": "<p>Reads <code>byteLength</code> number of bytes from <code>buf</code> at the specified <code>offset</code>\nand interprets the result as an unsigned integer. Supports up to 48\nbits of accuracy.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);\n\nconsole.log(buf.readUIntBE(0, 6).toString(16));\n// Prints: 1234567890ab\nconsole.log(buf.readUIntLE(0, 6).toString(16));\n// Prints: ab9078563412\nconsole.log(buf.readUIntBE(1, 6).toString(16));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.readUIntLE(offset, byteLength)",
"type": "method",
"name": "readUIntLE",
"meta": {
"added": [
"v0.11.15"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset and `byteLength` to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} ",
"name": "return",
"type": "integer"
},
"params": [
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`."
},
{
"textRaw": "`byteLength` {integer} Number of bytes to read. Must satisfy `0 < byteLength <= 6`. ",
"name": "byteLength",
"type": "integer",
"desc": "Number of bytes to read. Must satisfy `0 < byteLength <= 6`."
}
]
},
{
"params": [
{
"name": "offset"
},
{
"name": "byteLength"
}
]
}
],
"desc": "<p>Reads <code>byteLength</code> number of bytes from <code>buf</code> at the specified <code>offset</code>\nand interprets the result as an unsigned integer. Supports up to 48\nbits of accuracy.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);\n\nconsole.log(buf.readUIntBE(0, 6).toString(16));\n// Prints: 1234567890ab\nconsole.log(buf.readUIntLE(0, 6).toString(16));\n// Prints: ab9078563412\nconsole.log(buf.readUIntBE(1, 6).toString(16));\n// Throws ERR_OUT_OF_RANGE\n</code></pre>\n"
},
{
"textRaw": "buf.slice([start[, end]])",
"type": "method",
"name": "slice",
"meta": {
"added": [
"v0.3.0"
],
"changes": [
{
"version": "v7.1.0, v6.9.2",
"pr-url": "https://github.com/nodejs/node/pull/9341",
"description": "Coercing the offsets to integers now handles values outside the 32-bit integer range properly."
},
{
"version": "v7.0.0",
"pr-url": "https://github.com/nodejs/node/pull/9101",
"description": "All offsets are now coerced to integers before doing any calculations with them."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Buffer} ",
"name": "return",
"type": "Buffer"
},
"params": [
{
"textRaw": "`start` {integer} Where the new `Buffer` will start. **Default:** `0`. ",
"name": "start",
"type": "integer",
"default": "`0`",
"desc": "Where the new `Buffer` will start.",
"optional": true
},
{
"textRaw": "`end` {integer} Where the new `Buffer` will end (not inclusive). **Default:** [`buf.length`]. ",
"name": "end",
"type": "integer",
"default": "[`buf.length`]",
"desc": "Where the new `Buffer` will end (not inclusive).",
"optional": true
}
]
},
{
"params": [
{
"name": "start",
"optional": true
},
{
"name": "end",
"optional": true
}
]
}
],
"desc": "<p>Returns a new <code>Buffer</code> that references the same memory as the original, but\noffset and cropped by the <code>start</code> and <code>end</code> indices.</p>\n<p>Specifying <code>end</code> greater than <a href=\"#buffer_buf_length\"><code>buf.length</code></a> will return the same result as\nthat of <code>end</code> equal to <a href=\"#buffer_buf_length\"><code>buf.length</code></a>.</p>\n<p>Modifying the new <code>Buffer</code> slice will modify the memory in the original <code>Buffer</code>\nbecause the allocated memory of the two objects overlap.</p>\n<pre><code class=\"lang-js\">// Create a `Buffer` with the ASCII alphabet, take a slice, and modify one byte\n// from the original `Buffer`.\n\nconst buf1 = Buffer.allocUnsafe(26);\n\nfor (let i = 0; i &lt; 26; i++) {\n // 97 is the decimal ASCII value for &#39;a&#39;\n buf1[i] = i + 97;\n}\n\nconst buf2 = buf1.slice(0, 3);\n\nconsole.log(buf2.toString(&#39;ascii&#39;, 0, buf2.length));\n// Prints: abc\n\nbuf1[0] = 33;\n\nconsole.log(buf2.toString(&#39;ascii&#39;, 0, buf2.length));\n// Prints: !bc\n</code></pre>\n<p>Specifying negative indexes causes the slice to be generated relative to the\nend of <code>buf</code> rather than the beginning.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from(&#39;buffer&#39;);\n\nconsole.log(buf.slice(-6, -1).toString());\n// Prints: buffe\n// (Equivalent to buf.slice(0, 5))\n\nconsole.log(buf.slice(-6, -2).toString());\n// Prints: buff\n// (Equivalent to buf.slice(0, 4))\n\nconsole.log(buf.slice(-5, -2).toString());\n// Prints: uff\n// (Equivalent to buf.slice(1, 4))\n</code></pre>\n"
},
{
"textRaw": "buf.swap16()",
"type": "method",
"name": "swap16",
"meta": {
"added": [
"v5.10.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Buffer} A reference to `buf`. ",
"name": "return",
"type": "Buffer",
"desc": "A reference to `buf`."
},
"params": []
},
{
"params": []
}
],
"desc": "<p>Interprets <code>buf</code> as an array of unsigned 16-bit integers and swaps the\nbyte order <em>in-place</em>. Throws <a href=\"errors.html#ERR_INVALID_BUFFER_SIZE\"><code>ERR_INVALID_BUFFER_SIZE</code></a> if <a href=\"#buffer_buf_length\"><code>buf.length</code></a> is\nnot a multiple of 2.</p>\n<pre><code class=\"lang-js\">const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);\n\nconsole.log(buf1);\n// Prints: &lt;Buffer 01 02 03 04 05 06 07 08&gt;\n\nbuf1.swap16();\n\nconsole.log(buf1);\n// Prints: &lt;Buffer 02 01 04 03 06 05 08 07&gt;\n\nconst buf2 = Buffer.from([0x1, 0x2, 0x3]);\n\nbuf2.swap16();\n// Throws ERR_INVALID_BUFFER_SIZE\n</code></pre>\n"
},
{
"textRaw": "buf.swap32()",
"type": "method",
"name": "swap32",
"meta": {
"added": [
"v5.10.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Buffer} A reference to `buf`. ",
"name": "return",
"type": "Buffer",
"desc": "A reference to `buf`."
},
"params": []
},
{
"params": []
}
],
"desc": "<p>Interprets <code>buf</code> as an array of unsigned 32-bit integers and swaps the\nbyte order <em>in-place</em>. Throws <a href=\"errors.html#ERR_INVALID_BUFFER_SIZE\"><code>ERR_INVALID_BUFFER_SIZE</code></a> if <a href=\"#buffer_buf_length\"><code>buf.length</code></a> is\nnot a multiple of 4.</p>\n<pre><code class=\"lang-js\">const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);\n\nconsole.log(buf1);\n// Prints: &lt;Buffer 01 02 03 04 05 06 07 08&gt;\n\nbuf1.swap32();\n\nconsole.log(buf1);\n// Prints: &lt;Buffer 04 03 02 01 08 07 06 05&gt;\n\nconst buf2 = Buffer.from([0x1, 0x2, 0x3]);\n\nbuf2.swap32();\n// Throws ERR_INVALID_BUFFER_SIZE\n</code></pre>\n"
},
{
"textRaw": "buf.swap64()",
"type": "method",
"name": "swap64",
"meta": {
"added": [
"v6.3.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Buffer} A reference to `buf`. ",
"name": "return",
"type": "Buffer",
"desc": "A reference to `buf`."
},
"params": []
},
{
"params": []
}
],
"desc": "<p>Interprets <code>buf</code> as an array of 64-bit numbers and swaps byte order <em>in-place</em>.\nThrows <a href=\"errors.html#ERR_INVALID_BUFFER_SIZE\"><code>ERR_INVALID_BUFFER_SIZE</code></a> if <a href=\"#buffer_buf_length\"><code>buf.length</code></a> is not a multiple of 8.</p>\n<pre><code class=\"lang-js\">const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);\n\nconsole.log(buf1);\n// Prints: &lt;Buffer 01 02 03 04 05 06 07 08&gt;\n\nbuf1.swap64();\n\nconsole.log(buf1);\n// Prints: &lt;Buffer 08 07 06 05 04 03 02 01&gt;\n\nconst buf2 = Buffer.from([0x1, 0x2, 0x3]);\n\nbuf2.swap64();\n// Throws ERR_INVALID_BUFFER_SIZE\n</code></pre>\n<p>Note that JavaScript cannot encode 64-bit integers. This method is intended\nfor working with 64-bit floats.</p>\n"
},
{
"textRaw": "buf.toJSON()",
"type": "method",
"name": "toJSON",
"meta": {
"added": [
"v0.9.2"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Object} ",
"name": "return",
"type": "Object"
},
"params": []
},
{
"params": []
}
],
"desc": "<p>Returns a JSON representation of <code>buf</code>. <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify\"><code>JSON.stringify()</code></a> implicitly calls\nthis function when stringifying a <code>Buffer</code> instance.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]);\nconst json = JSON.stringify(buf);\n\nconsole.log(json);\n// Prints: {&quot;type&quot;:&quot;Buffer&quot;,&quot;data&quot;:[1,2,3,4,5]}\n\nconst copy = JSON.parse(json, (key, value) =&gt; {\n return value &amp;&amp; value.type === &#39;Buffer&#39; ?\n Buffer.from(value.data) :\n value;\n});\n\nconsole.log(copy);\n// Prints: &lt;Buffer 01 02 03 04 05&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.toString([encoding[, start[, end]]])",
"type": "method",
"name": "toString",
"meta": {
"added": [
"v0.1.90"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {string} ",
"name": "return",
"type": "string"
},
"params": [
{
"textRaw": "`encoding` {string} The character encoding to use. **Default:** `'utf8'`. ",
"name": "encoding",
"type": "string",
"default": "`'utf8'`",
"desc": "The character encoding to use.",
"optional": true
},
{
"textRaw": "`start` {integer} The byte offset to start decoding at. **Default:** `0`. ",
"name": "start",
"type": "integer",
"default": "`0`",
"desc": "The byte offset to start decoding at.",
"optional": true
},
{
"textRaw": "`end` {integer} The byte offset to stop decoding at (not inclusive). **Default:** [`buf.length`]. ",
"name": "end",
"type": "integer",
"default": "[`buf.length`]",
"desc": "The byte offset to stop decoding at (not inclusive).",
"optional": true
}
]
},
{
"params": [
{
"name": "encoding",
"optional": true
},
{
"name": "start",
"optional": true
},
{
"name": "end",
"optional": true
}
]
}
],
"desc": "<p>Decodes <code>buf</code> to a string according to the specified character encoding in\n<code>encoding</code>. <code>start</code> and <code>end</code> may be passed to decode only a subset of <code>buf</code>.</p>\n<p>The maximum length of a string instance (in UTF-16 code units) is available\nas <a href=\"#buffer_buffer_constants_max_string_length\"><code>buffer.constants.MAX_STRING_LENGTH</code></a>.</p>\n<pre><code class=\"lang-js\">const buf1 = Buffer.allocUnsafe(26);\n\nfor (let i = 0; i &lt; 26; i++) {\n // 97 is the decimal ASCII value for &#39;a&#39;\n buf1[i] = i + 97;\n}\n\nconsole.log(buf1.toString(&#39;ascii&#39;));\n// Prints: abcdefghijklmnopqrstuvwxyz\nconsole.log(buf1.toString(&#39;ascii&#39;, 0, 5));\n// Prints: abcde\n\nconst buf2 = Buffer.from(&#39;tést&#39;);\n\nconsole.log(buf2.toString(&#39;hex&#39;));\n// Prints: 74c3a97374\nconsole.log(buf2.toString(&#39;utf8&#39;, 0, 3));\n// Prints: té\nconsole.log(buf2.toString(undefined, 0, 3));\n// Prints: té\n</code></pre>\n"
},
{
"textRaw": "buf.values()",
"type": "method",
"name": "values",
"meta": {
"added": [
"v1.1.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Iterator} ",
"name": "return",
"type": "Iterator"
},
"params": []
},
{
"params": []
}
],
"desc": "<p>Creates and returns an <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols\">iterator</a> for <code>buf</code> values (bytes). This function is\ncalled automatically when a <code>Buffer</code> is used in a <code>for..of</code> statement.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.from(&#39;buffer&#39;);\n\nfor (const value of buf.values()) {\n console.log(value);\n}\n// Prints:\n// 98\n// 117\n// 102\n// 102\n// 101\n// 114\n\nfor (const value of buf) {\n console.log(value);\n}\n// Prints:\n// 98\n// 117\n// 102\n// 102\n// 101\n// 114\n</code></pre>\n"
},
{
"textRaw": "buf.write(string[, offset[, length]][, encoding])",
"type": "method",
"name": "write",
"meta": {
"added": [
"v0.1.90"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} Number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "Number of bytes written."
},
"params": [
{
"textRaw": "`string` {string} String to write to `buf`. ",
"name": "string",
"type": "string",
"desc": "String to write to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write `string`. **Default:** `0`. ",
"name": "offset",
"type": "integer",
"default": "`0`",
"desc": "Number of bytes to skip before starting to write `string`.",
"optional": true
},
{
"textRaw": "`length` {integer} Number of bytes to write. **Default:** `buf.length - offset`. ",
"name": "length",
"type": "integer",
"default": "`buf.length - offset`",
"desc": "Number of bytes to write.",
"optional": true
},
{
"textRaw": "`encoding` {string} The character encoding of `string`. **Default:** `'utf8'`. ",
"name": "encoding",
"type": "string",
"default": "`'utf8'`",
"desc": "The character encoding of `string`.",
"optional": true
}
]
},
{
"params": [
{
"name": "string"
},
{
"name": "offset",
"optional": true
},
{
"name": "length",
"optional": true
},
{
"name": "encoding",
"optional": true
}
]
}
],
"desc": "<p>Writes <code>string</code> to <code>buf</code> at <code>offset</code> according to the character encoding in\n<code>encoding</code>. The <code>length</code> parameter is the number of bytes to write. If <code>buf</code> did\nnot contain enough space to fit the entire string, only part of <code>string</code> will be\nwritten. However, partially encoded characters will not be written.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.alloc(256);\n\nconst len = buf.write(&#39;\\u00bd + \\u00bc = \\u00be&#39;, 0);\n\nconsole.log(`${len} bytes: ${buf.toString(&#39;utf8&#39;, 0, len)}`);\n// Prints: 12 bytes: ½ + ¼ = ¾\n</code></pre>\n"
},
{
"textRaw": "buf.writeDoubleBE(value, offset)",
"type": "method",
"name": "writeDoubleBE",
"meta": {
"added": [
"v0.11.15"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {number} Number to be written to `buf`. ",
"name": "value",
"type": "number",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 8`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 8`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
}
],
"desc": "<p>Writes <code>value</code> to <code>buf</code> at the specified <code>offset</code> with specified endian\nformat (<code>writeDoubleBE()</code> writes big endian, <code>writeDoubleLE()</code> writes little\nendian). <code>value</code> <em>should</em> be a valid 64-bit double. Behavior is undefined when\n<code>value</code> is anything other than a 64-bit double.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(8);\n\nbuf.writeDoubleBE(0xdeadbeefcafebabe, 0);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 43 eb d5 b7 dd f9 5f d7&gt;\n\nbuf.writeDoubleLE(0xdeadbeefcafebabe, 0);\n\nconsole.log(buf);\n// Prints: &lt;Buffer d7 5f f9 dd b7 d5 eb 43&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeDoubleLE(value, offset)",
"type": "method",
"name": "writeDoubleLE",
"meta": {
"added": [
"v0.11.15"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {number} Number to be written to `buf`. ",
"name": "value",
"type": "number",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 8`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 8`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
}
],
"desc": "<p>Writes <code>value</code> to <code>buf</code> at the specified <code>offset</code> with specified endian\nformat (<code>writeDoubleBE()</code> writes big endian, <code>writeDoubleLE()</code> writes little\nendian). <code>value</code> <em>should</em> be a valid 64-bit double. Behavior is undefined when\n<code>value</code> is anything other than a 64-bit double.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(8);\n\nbuf.writeDoubleBE(0xdeadbeefcafebabe, 0);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 43 eb d5 b7 dd f9 5f d7&gt;\n\nbuf.writeDoubleLE(0xdeadbeefcafebabe, 0);\n\nconsole.log(buf);\n// Prints: &lt;Buffer d7 5f f9 dd b7 d5 eb 43&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeFloatBE(value, offset)",
"type": "method",
"name": "writeFloatBE",
"meta": {
"added": [
"v0.11.15"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {number} Number to be written to `buf`. ",
"name": "value",
"type": "number",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
}
],
"desc": "<p>Writes <code>value</code> to <code>buf</code> at the specified <code>offset</code> with specified endian\nformat (<code>writeFloatBE()</code> writes big endian, <code>writeFloatLE()</code> writes little\nendian). <code>value</code> <em>should</em> be a valid 32-bit float. Behavior is undefined when\n<code>value</code> is anything other than a 32-bit float.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(4);\n\nbuf.writeFloatBE(0xcafebabe, 0);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 4f 4a fe bb&gt;\n\nbuf.writeFloatLE(0xcafebabe, 0);\n\nconsole.log(buf);\n// Prints: &lt;Buffer bb fe 4a 4f&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeFloatLE(value, offset)",
"type": "method",
"name": "writeFloatLE",
"meta": {
"added": [
"v0.11.15"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {number} Number to be written to `buf`. ",
"name": "value",
"type": "number",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
}
],
"desc": "<p>Writes <code>value</code> to <code>buf</code> at the specified <code>offset</code> with specified endian\nformat (<code>writeFloatBE()</code> writes big endian, <code>writeFloatLE()</code> writes little\nendian). <code>value</code> <em>should</em> be a valid 32-bit float. Behavior is undefined when\n<code>value</code> is anything other than a 32-bit float.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(4);\n\nbuf.writeFloatBE(0xcafebabe, 0);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 4f 4a fe bb&gt;\n\nbuf.writeFloatLE(0xcafebabe, 0);\n\nconsole.log(buf);\n// Prints: &lt;Buffer bb fe 4a 4f&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeInt8(value, offset)",
"type": "method",
"name": "writeInt8",
"meta": {
"added": [
"v0.5.0"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {integer} Number to be written to `buf`. ",
"name": "value",
"type": "integer",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 1`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 1`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
}
],
"desc": "<p>Writes <code>value</code> to <code>buf</code> at the specified <code>offset</code>. <code>value</code> <em>should</em> be a valid\nsigned 8-bit integer. Behavior is undefined when <code>value</code> is anything other than\na signed 8-bit integer.</p>\n<p><code>value</code> is interpreted and written as a two&#39;s complement signed integer.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(2);\n\nbuf.writeInt8(2, 0);\nbuf.writeInt8(-2, 1);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 02 fe&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeInt16BE(value, offset)",
"type": "method",
"name": "writeInt16BE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {integer} Number to be written to `buf`. ",
"name": "value",
"type": "integer",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
}
],
"desc": "<p>Writes <code>value</code> to <code>buf</code> at the specified <code>offset</code> with specified endian\nformat (<code>writeInt16BE()</code> writes big endian, <code>writeInt16LE()</code> writes little\nendian). <code>value</code> <em>should</em> be a valid signed 16-bit integer. Behavior is\nundefined when <code>value</code> is anything other than a signed 16-bit integer.</p>\n<p><code>value</code> is interpreted and written as a two&#39;s complement signed integer.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(4);\n\nbuf.writeInt16BE(0x0102, 0);\nbuf.writeInt16LE(0x0304, 2);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 01 02 04 03&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeInt16LE(value, offset)",
"type": "method",
"name": "writeInt16LE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {integer} Number to be written to `buf`. ",
"name": "value",
"type": "integer",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
}
],
"desc": "<p>Writes <code>value</code> to <code>buf</code> at the specified <code>offset</code> with specified endian\nformat (<code>writeInt16BE()</code> writes big endian, <code>writeInt16LE()</code> writes little\nendian). <code>value</code> <em>should</em> be a valid signed 16-bit integer. Behavior is\nundefined when <code>value</code> is anything other than a signed 16-bit integer.</p>\n<p><code>value</code> is interpreted and written as a two&#39;s complement signed integer.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(4);\n\nbuf.writeInt16BE(0x0102, 0);\nbuf.writeInt16LE(0x0304, 2);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 01 02 04 03&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeInt32BE(value, offset)",
"type": "method",
"name": "writeInt32BE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {integer} Number to be written to `buf`. ",
"name": "value",
"type": "integer",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
}
],
"desc": "<p>Writes <code>value</code> to <code>buf</code> at the specified <code>offset</code> with specified endian\nformat (<code>writeInt32BE()</code> writes big endian, <code>writeInt32LE()</code> writes little\nendian). <code>value</code> <em>should</em> be a valid signed 32-bit integer. Behavior is\nundefined when <code>value</code> is anything other than a signed 32-bit integer.</p>\n<p><code>value</code> is interpreted and written as a two&#39;s complement signed integer.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(8);\n\nbuf.writeInt32BE(0x01020304, 0);\nbuf.writeInt32LE(0x05060708, 4);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 01 02 03 04 08 07 06 05&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeInt32LE(value, offset)",
"type": "method",
"name": "writeInt32LE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {integer} Number to be written to `buf`. ",
"name": "value",
"type": "integer",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
}
],
"desc": "<p>Writes <code>value</code> to <code>buf</code> at the specified <code>offset</code> with specified endian\nformat (<code>writeInt32BE()</code> writes big endian, <code>writeInt32LE()</code> writes little\nendian). <code>value</code> <em>should</em> be a valid signed 32-bit integer. Behavior is\nundefined when <code>value</code> is anything other than a signed 32-bit integer.</p>\n<p><code>value</code> is interpreted and written as a two&#39;s complement signed integer.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(8);\n\nbuf.writeInt32BE(0x01020304, 0);\nbuf.writeInt32LE(0x05060708, 4);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 01 02 03 04 08 07 06 05&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeIntBE(value, offset, byteLength)",
"type": "method",
"name": "writeIntBE",
"meta": {
"added": [
"v0.11.15"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset and `byteLength` to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {integer} Number to be written to `buf`. ",
"name": "value",
"type": "integer",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`."
},
{
"textRaw": "`byteLength` {integer} Number of bytes to write. Must satisfy `0 < byteLength <= 6`. ",
"name": "byteLength",
"type": "integer",
"desc": "Number of bytes to write. Must satisfy `0 < byteLength <= 6`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
},
{
"name": "byteLength"
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
},
{
"name": "byteLength"
}
]
}
],
"desc": "<p>Writes <code>byteLength</code> bytes of <code>value</code> to <code>buf</code> at the specified <code>offset</code>.\nSupports up to 48 bits of accuracy. Behavior is undefined when <code>value</code> is\nanything other than a signed integer.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(6);\n\nbuf.writeIntBE(0x1234567890ab, 0, 6);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 12 34 56 78 90 ab&gt;\n\nbuf.writeIntLE(0x1234567890ab, 0, 6);\n\nconsole.log(buf);\n// Prints: &lt;Buffer ab 90 78 56 34 12&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeIntLE(value, offset, byteLength)",
"type": "method",
"name": "writeIntLE",
"meta": {
"added": [
"v0.11.15"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset and `byteLength` to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {integer} Number to be written to `buf`. ",
"name": "value",
"type": "integer",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`."
},
{
"textRaw": "`byteLength` {integer} Number of bytes to write. Must satisfy `0 < byteLength <= 6`. ",
"name": "byteLength",
"type": "integer",
"desc": "Number of bytes to write. Must satisfy `0 < byteLength <= 6`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
},
{
"name": "byteLength"
}
]
}
],
"desc": "<p>Writes <code>byteLength</code> bytes of <code>value</code> to <code>buf</code> at the specified <code>offset</code>.\nSupports up to 48 bits of accuracy. Behavior is undefined when <code>value</code> is\nanything other than a signed integer.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(6);\n\nbuf.writeIntBE(0x1234567890ab, 0, 6);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 12 34 56 78 90 ab&gt;\n\nbuf.writeIntLE(0x1234567890ab, 0, 6);\n\nconsole.log(buf);\n// Prints: &lt;Buffer ab 90 78 56 34 12&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeUInt8(value, offset)",
"type": "method",
"name": "writeUInt8",
"meta": {
"added": [
"v0.5.0"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {integer} Number to be written to `buf`. ",
"name": "value",
"type": "integer",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 1`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 1`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
}
],
"desc": "<p>Writes <code>value</code> to <code>buf</code> at the specified <code>offset</code>. <code>value</code> <em>should</em> be a\nvalid unsigned 8-bit integer. Behavior is undefined when <code>value</code> is anything\nother than an unsigned 8-bit integer.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(4);\n\nbuf.writeUInt8(0x3, 0);\nbuf.writeUInt8(0x4, 1);\nbuf.writeUInt8(0x23, 2);\nbuf.writeUInt8(0x42, 3);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 03 04 23 42&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeUInt16BE(value, offset)",
"type": "method",
"name": "writeUInt16BE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {integer} Number to be written to `buf`. ",
"name": "value",
"type": "integer",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
}
],
"desc": "<p>Writes <code>value</code> to <code>buf</code> at the specified <code>offset</code> with specified endian\nformat (<code>writeUInt16BE()</code> writes big endian, <code>writeUInt16LE()</code> writes little\nendian). <code>value</code> should be a valid unsigned 16-bit integer. Behavior is\nundefined when <code>value</code> is anything other than an unsigned 16-bit integer.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(4);\n\nbuf.writeUInt16BE(0xdead, 0);\nbuf.writeUInt16BE(0xbeef, 2);\n\nconsole.log(buf);\n// Prints: &lt;Buffer de ad be ef&gt;\n\nbuf.writeUInt16LE(0xdead, 0);\nbuf.writeUInt16LE(0xbeef, 2);\n\nconsole.log(buf);\n// Prints: &lt;Buffer ad de ef be&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeUInt16LE(value, offset)",
"type": "method",
"name": "writeUInt16LE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {integer} Number to be written to `buf`. ",
"name": "value",
"type": "integer",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
}
],
"desc": "<p>Writes <code>value</code> to <code>buf</code> at the specified <code>offset</code> with specified endian\nformat (<code>writeUInt16BE()</code> writes big endian, <code>writeUInt16LE()</code> writes little\nendian). <code>value</code> should be a valid unsigned 16-bit integer. Behavior is\nundefined when <code>value</code> is anything other than an unsigned 16-bit integer.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(4);\n\nbuf.writeUInt16BE(0xdead, 0);\nbuf.writeUInt16BE(0xbeef, 2);\n\nconsole.log(buf);\n// Prints: &lt;Buffer de ad be ef&gt;\n\nbuf.writeUInt16LE(0xdead, 0);\nbuf.writeUInt16LE(0xbeef, 2);\n\nconsole.log(buf);\n// Prints: &lt;Buffer ad de ef be&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeUInt32BE(value, offset)",
"type": "method",
"name": "writeUInt32BE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {integer} Number to be written to `buf`. ",
"name": "value",
"type": "integer",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
}
],
"desc": "<p>Writes <code>value</code> to <code>buf</code> at the specified <code>offset</code> with specified endian\nformat (<code>writeUInt32BE()</code> writes big endian, <code>writeUInt32LE()</code> writes little\nendian). <code>value</code> should be a valid unsigned 32-bit integer. Behavior is\nundefined when <code>value</code> is anything other than an unsigned 32-bit integer.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(4);\n\nbuf.writeUInt32BE(0xfeedface, 0);\n\nconsole.log(buf);\n// Prints: &lt;Buffer fe ed fa ce&gt;\n\nbuf.writeUInt32LE(0xfeedface, 0);\n\nconsole.log(buf);\n// Prints: &lt;Buffer ce fa ed fe&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeUInt32LE(value, offset)",
"type": "method",
"name": "writeUInt32LE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {integer} Number to be written to `buf`. ",
"name": "value",
"type": "integer",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
}
]
}
],
"desc": "<p>Writes <code>value</code> to <code>buf</code> at the specified <code>offset</code> with specified endian\nformat (<code>writeUInt32BE()</code> writes big endian, <code>writeUInt32LE()</code> writes little\nendian). <code>value</code> should be a valid unsigned 32-bit integer. Behavior is\nundefined when <code>value</code> is anything other than an unsigned 32-bit integer.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(4);\n\nbuf.writeUInt32BE(0xfeedface, 0);\n\nconsole.log(buf);\n// Prints: &lt;Buffer fe ed fa ce&gt;\n\nbuf.writeUInt32LE(0xfeedface, 0);\n\nconsole.log(buf);\n// Prints: &lt;Buffer ce fa ed fe&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeUIntBE(value, offset, byteLength)",
"type": "method",
"name": "writeUIntBE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset and `byteLength` to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {integer} Number to be written to `buf`. ",
"name": "value",
"type": "integer",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`."
},
{
"textRaw": "`byteLength` {integer} Number of bytes to write. Must satisfy `0 < byteLength <= 6`. ",
"name": "byteLength",
"type": "integer",
"desc": "Number of bytes to write. Must satisfy `0 < byteLength <= 6`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
},
{
"name": "byteLength"
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
},
{
"name": "byteLength"
}
]
}
],
"desc": "<p>Writes <code>byteLength</code> bytes of <code>value</code> to <code>buf</code> at the specified <code>offset</code>.\nSupports up to 48 bits of accuracy. Behavior is undefined when <code>value</code> is\nanything other than an unsigned integer.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(6);\n\nbuf.writeUIntBE(0x1234567890ab, 0, 6);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 12 34 56 78 90 ab&gt;\n\nbuf.writeUIntLE(0x1234567890ab, 0, 6);\n\nconsole.log(buf);\n// Prints: &lt;Buffer ab 90 78 56 34 12&gt;\n</code></pre>\n"
},
{
"textRaw": "buf.writeUIntLE(value, offset, byteLength)",
"type": "method",
"name": "writeUIntLE",
"meta": {
"added": [
"v0.5.5"
],
"changes": [
{
"version": "v10.0.0",
"pr-url": "https://github.com/nodejs/node/pull/18395",
"description": "Removed `noAssert` and no implicit coercion of the offset and `byteLength` to `uint32` anymore."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {integer} `offset` plus the number of bytes written. ",
"name": "return",
"type": "integer",
"desc": "`offset` plus the number of bytes written."
},
"params": [
{
"textRaw": "`value` {integer} Number to be written to `buf`. ",
"name": "value",
"type": "integer",
"desc": "Number to be written to `buf`."
},
{
"textRaw": "`offset` {integer} Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`. ",
"name": "offset",
"type": "integer",
"desc": "Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`."
},
{
"textRaw": "`byteLength` {integer} Number of bytes to write. Must satisfy `0 < byteLength <= 6`. ",
"name": "byteLength",
"type": "integer",
"desc": "Number of bytes to write. Must satisfy `0 < byteLength <= 6`."
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "offset"
},
{
"name": "byteLength"
}
]
}
],
"desc": "<p>Writes <code>byteLength</code> bytes of <code>value</code> to <code>buf</code> at the specified <code>offset</code>.\nSupports up to 48 bits of accuracy. Behavior is undefined when <code>value</code> is\nanything other than an unsigned integer.</p>\n<pre><code class=\"lang-js\">const buf = Buffer.allocUnsafe(6);\n\nbuf.writeUIntBE(0x1234567890ab, 0, 6);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 12 34 56 78 90 ab&gt;\n\nbuf.writeUIntLE(0x1234567890ab, 0, 6);\n\nconsole.log(buf);\n// Prints: &lt;Buffer ab 90 78 56 34 12&gt;\n</code></pre>\n"
}
],
"signatures": [
{
"params": [
{
"textRaw": "`array` {integer[]} An array of bytes to copy from. ",
"name": "array",
"type": "integer[]",
"desc": "An array of bytes to copy from."
}
],
"desc": "<p>Allocates a new <code>Buffer</code> using an <code>array</code> of octets.</p>\n<pre><code class=\"lang-js\">// Creates a new Buffer containing the UTF-8 bytes of the string &#39;buffer&#39;\nconst buf = new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);\n</code></pre>\n"
},
{
"params": [
{
"name": "array"
}
],
"desc": "<p>Allocates a new <code>Buffer</code> using an <code>array</code> of octets.</p>\n<pre><code class=\"lang-js\">// Creates a new Buffer containing the UTF-8 bytes of the string &#39;buffer&#39;\nconst buf = new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);\n</code></pre>\n"
},
{
"params": [
{
"textRaw": "`arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An [`ArrayBuffer`], [`SharedArrayBuffer`] or the `.buffer` property of a [`TypedArray`]. ",
"name": "arrayBuffer",
"type": "ArrayBuffer|SharedArrayBuffer",
"desc": "An [`ArrayBuffer`], [`SharedArrayBuffer`] or the `.buffer` property of a [`TypedArray`]."
},
{
"textRaw": "`byteOffset` {integer} Index of first byte to expose. **Default:** `0`. ",
"name": "byteOffset",
"type": "integer",
"default": "`0`",
"desc": "Index of first byte to expose.",
"optional": true
},
{
"textRaw": "`length` {integer} Number of bytes to expose. **Default:** `arrayBuffer.length - byteOffset`. ",
"name": "length",
"type": "integer",
"default": "`arrayBuffer.length - byteOffset`",
"desc": "Number of bytes to expose.",
"optional": true
}
],
"desc": "<p>Stability: 0 - Deprecated: Use\n<a href=\"#buffer_class_method_buffer_from_arraybuffer_byteoffset_length\"><code>Buffer.from(arrayBuffer[, byteOffset[, length]])</code></a>\ninstead.</p>\n<p>This creates a view of the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer\"><code>ArrayBuffer</code></a> or <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer\"><code>SharedArrayBuffer</code></a> without\ncopying the underlying memory. For example, when passed a reference to the\n<code>.buffer</code> property of a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\"><code>TypedArray</code></a> instance, the newly created <code>Buffer</code> will\nshare the same allocated memory as the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\"><code>TypedArray</code></a>.</p>\n<p>The optional <code>byteOffset</code> and <code>length</code> arguments specify a memory range within\nthe <code>arrayBuffer</code> that will be shared by the <code>Buffer</code>.</p>\n<pre><code class=\"lang-js\">const arr = new Uint16Array(2);\n\narr[0] = 5000;\narr[1] = 4000;\n\n// Shares memory with `arr`\nconst buf = new Buffer(arr.buffer);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 88 13 a0 0f&gt;\n\n// Changing the original Uint16Array changes the Buffer also\narr[1] = 6000;\n\nconsole.log(buf);\n// Prints: &lt;Buffer 88 13 70 17&gt;\n</code></pre>\n"
},
{
"params": [
{
"name": "arrayBuffer"
},
{
"name": "byteOffset",
"optional": true
},
{
"name": "length",
"optional": true
}
],
"desc": "<p>Stability: 0 - Deprecated: Use\n<a href=\"#buffer_class_method_buffer_from_arraybuffer_byteoffset_length\"><code>Buffer.from(arrayBuffer[, byteOffset[, length]])</code></a>\ninstead.</p>\n<p>This creates a view of the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer\"><code>ArrayBuffer</code></a> or <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer\"><code>SharedArrayBuffer</code></a> without\ncopying the underlying memory. For example, when passed a reference to the\n<code>.buffer</code> property of a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\"><code>TypedArray</code></a> instance, the newly created <code>Buffer</code> will\nshare the same allocated memory as the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\"><code>TypedArray</code></a>.</p>\n<p>The optional <code>byteOffset</code> and <code>length</code> arguments specify a memory range within\nthe <code>arrayBuffer</code> that will be shared by the <code>Buffer</code>.</p>\n<pre><code class=\"lang-js\">const arr = new Uint16Array(2);\n\narr[0] = 5000;\narr[1] = 4000;\n\n// Shares memory with `arr`\nconst buf = new Buffer(arr.buffer);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 88 13 a0 0f&gt;\n\n// Changing the original Uint16Array changes the Buffer also\narr[1] = 6000;\n\nconsole.log(buf);\n// Prints: &lt;Buffer 88 13 70 17&gt;\n</code></pre>\n"
},
{
"params": [
{
"textRaw": "`buffer` {Buffer|Uint8Array} An existing `Buffer` or [`Uint8Array`] from which to copy data. ",
"name": "buffer",
"type": "Buffer|Uint8Array",
"desc": "An existing `Buffer` or [`Uint8Array`] from which to copy data."
}
],
"desc": "<p>Copies the passed <code>buffer</code> data onto a new <code>Buffer</code> instance.</p>\n<pre><code class=\"lang-js\">const buf1 = new Buffer(&#39;buffer&#39;);\nconst buf2 = new Buffer(buf1);\n\nbuf1[0] = 0x61;\n\nconsole.log(buf1.toString());\n// Prints: auffer\nconsole.log(buf2.toString());\n// Prints: buffer\n</code></pre>\n"
},
{
"params": [
{
"name": "buffer"
}
],
"desc": "<p>Copies the passed <code>buffer</code> data onto a new <code>Buffer</code> instance.</p>\n<pre><code class=\"lang-js\">const buf1 = new Buffer(&#39;buffer&#39;);\nconst buf2 = new Buffer(buf1);\n\nbuf1[0] = 0x61;\n\nconsole.log(buf1.toString());\n// Prints: auffer\nconsole.log(buf2.toString());\n// Prints: buffer\n</code></pre>\n"
},
{
"params": [
{
"textRaw": "`size` {integer} The desired length of the new `Buffer`. ",
"name": "size",
"type": "integer",
"desc": "The desired length of the new `Buffer`."
}
],
"desc": "<p>Stability: 0 - Deprecated: Use <a href=\"#buffer_class_method_buffer_alloc_size_fill_encoding\"><code>Buffer.alloc()</code></a> instead (also see\n<a href=\"#buffer_class_method_buffer_allocunsafe_size\"><code>Buffer.allocUnsafe()</code></a>).</p>\n<p>Allocates a new <code>Buffer</code> of <code>size</code> bytes. If <code>size</code> is larger than\n<a href=\"#buffer_buffer_constants_max_length\"><code>buffer.constants.MAX_LENGTH</code></a> or smaller than 0, <a href=\"errors.html#ERR_INVALID_OPT_VALUE\"><code>ERR_INVALID_OPT_VALUE</code></a> is\nthrown. A zero-length <code>Buffer</code> is created if <code>size</code> is 0.</p>\n<p>Prior to Node.js 8.0.0, the underlying memory for <code>Buffer</code> instances\ncreated in this way is <em>not initialized</em>. The contents of a newly created\n<code>Buffer</code> are unknown and <em>may contain sensitive data</em>. Use\n<a href=\"#buffer_class_method_buffer_alloc_size_fill_encoding\"><code>Buffer.alloc(size)</code></a> instead to initialize a <code>Buffer</code>\nwith zeroes.</p>\n<pre><code class=\"lang-js\">const buf = new Buffer(10);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 00 00 00 00 00 00 00 00 00 00&gt;\n</code></pre>\n"
},
{
"params": [
{
"name": "size"
}
],
"desc": "<p>Stability: 0 - Deprecated: Use <a href=\"#buffer_class_method_buffer_alloc_size_fill_encoding\"><code>Buffer.alloc()</code></a> instead (also see\n<a href=\"#buffer_class_method_buffer_allocunsafe_size\"><code>Buffer.allocUnsafe()</code></a>).</p>\n<p>Allocates a new <code>Buffer</code> of <code>size</code> bytes. If <code>size</code> is larger than\n<a href=\"#buffer_buffer_constants_max_length\"><code>buffer.constants.MAX_LENGTH</code></a> or smaller than 0, <a href=\"errors.html#ERR_INVALID_OPT_VALUE\"><code>ERR_INVALID_OPT_VALUE</code></a> is\nthrown. A zero-length <code>Buffer</code> is created if <code>size</code> is 0.</p>\n<p>Prior to Node.js 8.0.0, the underlying memory for <code>Buffer</code> instances\ncreated in this way is <em>not initialized</em>. The contents of a newly created\n<code>Buffer</code> are unknown and <em>may contain sensitive data</em>. Use\n<a href=\"#buffer_class_method_buffer_alloc_size_fill_encoding\"><code>Buffer.alloc(size)</code></a> instead to initialize a <code>Buffer</code>\nwith zeroes.</p>\n<pre><code class=\"lang-js\">const buf = new Buffer(10);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 00 00 00 00 00 00 00 00 00 00&gt;\n</code></pre>\n"
},
{
"params": [
{
"textRaw": "`string` {string} String to encode. ",
"name": "string",
"type": "string",
"desc": "String to encode."
},
{
"textRaw": "`encoding` {string} The encoding of `string`. **Default:** `'utf8'`. ",
"name": "encoding",
"type": "string",
"default": "`'utf8'`",
"desc": "The encoding of `string`.",
"optional": true
}
],
"desc": "<p>Stability: 0 - Deprecated:\nUse <a href=\"#buffer_class_method_buffer_from_string_encoding\"><code>Buffer.from(string[, encoding])</code></a> instead.</p>\n<p>Creates a new <code>Buffer</code> containing <code>string</code>. The <code>encoding</code> parameter identifies\nthe character encoding of <code>string</code>.</p>\n<pre><code class=\"lang-js\">const buf1 = new Buffer(&#39;this is a tést&#39;);\nconst buf2 = new Buffer(&#39;7468697320697320612074c3a97374&#39;, &#39;hex&#39;);\n\nconsole.log(buf1.toString());\n// Prints: this is a tést\nconsole.log(buf2.toString());\n// Prints: this is a tést\nconsole.log(buf1.toString(&#39;ascii&#39;));\n// Prints: this is a tC)st\n</code></pre>\n"
},
{
"params": [
{
"name": "string"
},
{
"name": "encoding",
"optional": true
}
],
"desc": "<p>Stability: 0 - Deprecated:\nUse <a href=\"#buffer_class_method_buffer_from_string_encoding\"><code>Buffer.from(string[, encoding])</code></a> instead.</p>\n<p>Creates a new <code>Buffer</code> containing <code>string</code>. The <code>encoding</code> parameter identifies\nthe character encoding of <code>string</code>.</p>\n<pre><code class=\"lang-js\">const buf1 = new Buffer(&#39;this is a tést&#39;);\nconst buf2 = new Buffer(&#39;7468697320697320612074c3a97374&#39;, &#39;hex&#39;);\n\nconsole.log(buf1.toString());\n// Prints: this is a tést\nconsole.log(buf2.toString());\n// Prints: this is a tést\nconsole.log(buf1.toString(&#39;ascii&#39;));\n// Prints: this is a tC)st\n</code></pre>\n"
}
]
},
{
"textRaw": "Class: SlowBuffer",
"type": "class",
"name": "SlowBuffer",
"meta": {
"deprecated": [
"v6.0.0"
],
"changes": []
},
"stability": 0,
"stabilityText": "Deprecated: Use [`Buffer.allocUnsafeSlow()`] instead.",
"desc": "<p>Returns an un-pooled <code>Buffer</code>.</p>\n<p>In order to avoid the garbage collection overhead of creating many individually\nallocated <code>Buffer</code> instances, by default allocations under 4KB are sliced from a\nsingle larger allocated object.</p>\n<p>In the case where a developer may need to retain a small chunk of memory from a\npool for an indeterminate amount of time, it may be appropriate to create an\nun-pooled <code>Buffer</code> instance using <code>SlowBuffer</code> then copy out the relevant bits.</p>\n<pre><code class=\"lang-js\">// Need to keep around a few small chunks of memory\nconst store = [];\n\nsocket.on(&#39;readable&#39;, () =&gt; {\n const data = socket.read();\n\n // Allocate for retained data\n const sb = SlowBuffer(10);\n\n // Copy the data into the new allocation\n data.copy(sb, 0, 0, 10);\n\n store.push(sb);\n});\n</code></pre>\n<p>Use of <code>SlowBuffer</code> should be used only as a last resort <em>after</em> a developer\nhas observed undue memory retention in their applications.</p>\n",
"signatures": [
{
"params": [
{
"textRaw": "`size` {integer} The desired length of the new `SlowBuffer`. ",
"name": "size",
"type": "integer",
"desc": "The desired length of the new `SlowBuffer`."
}
],
"desc": "<p>Allocates a new <code>Buffer</code> of <code>size</code> bytes. If <code>size</code> is larger than\n<a href=\"#buffer_buffer_constants_max_length\"><code>buffer.constants.MAX_LENGTH</code></a> or smaller than 0, <a href=\"errors.html#ERR_INVALID_OPT_VALUE\"><code>ERR_INVALID_OPT_VALUE</code></a> is\nthrown. A zero-length <code>Buffer</code> is created if <code>size</code> is 0.</p>\n<p>The underlying memory for <code>SlowBuffer</code> instances is <em>not initialized</em>. The\ncontents of a newly created <code>SlowBuffer</code> are unknown and may contain sensitive\ndata. Use <a href=\"#buffer_buf_fill_value_offset_end_encoding\"><code>buf.fill(0)</code></a> to initialize a <code>SlowBuffer</code> with\nzeroes.</p>\n<pre><code class=\"lang-js\">const { SlowBuffer } = require(&#39;buffer&#39;);\n\nconst buf = new SlowBuffer(5);\n\nconsole.log(buf);\n// Prints: (contents may vary): &lt;Buffer 78 e0 82 02 01&gt;\n\nbuf.fill(0);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 00 00 00 00 00&gt;\n</code></pre>\n"
},
{
"params": [
{
"name": "size"
}
],
"desc": "<p>Allocates a new <code>Buffer</code> of <code>size</code> bytes. If <code>size</code> is larger than\n<a href=\"#buffer_buffer_constants_max_length\"><code>buffer.constants.MAX_LENGTH</code></a> or smaller than 0, <a href=\"errors.html#ERR_INVALID_OPT_VALUE\"><code>ERR_INVALID_OPT_VALUE</code></a> is\nthrown. A zero-length <code>Buffer</code> is created if <code>size</code> is 0.</p>\n<p>The underlying memory for <code>SlowBuffer</code> instances is <em>not initialized</em>. The\ncontents of a newly created <code>SlowBuffer</code> are unknown and may contain sensitive\ndata. Use <a href=\"#buffer_buf_fill_value_offset_end_encoding\"><code>buf.fill(0)</code></a> to initialize a <code>SlowBuffer</code> with\nzeroes.</p>\n<pre><code class=\"lang-js\">const { SlowBuffer } = require(&#39;buffer&#39;);\n\nconst buf = new SlowBuffer(5);\n\nconsole.log(buf);\n// Prints: (contents may vary): &lt;Buffer 78 e0 82 02 01&gt;\n\nbuf.fill(0);\n\nconsole.log(buf);\n// Prints: &lt;Buffer 00 00 00 00 00&gt;\n</code></pre>\n"
}
]
}
],
"properties": [
{
"textRaw": "`INSPECT_MAX_BYTES` {integer} **Default:** `50` ",
"type": "integer",
"name": "INSPECT_MAX_BYTES",
"meta": {
"added": [
"v0.5.4"
],
"changes": []
},
"default": "`50`",
"desc": "<p>Returns the maximum number of bytes that will be returned when\n<code>buf.inspect()</code> is called. This can be overridden by user modules. See\n<a href=\"util.html#util_util_inspect_object_options\"><code>util.inspect()</code></a> for more details on <code>buf.inspect()</code> behavior.</p>\n<p>Note that this is a property on the <code>buffer</code> module returned by\n<code>require(&#39;buffer&#39;)</code>, not on the <code>Buffer</code> global or a <code>Buffer</code> instance.</p>\n"
},
{
"textRaw": "`kMaxLength` {integer} The largest size allowed for a single `Buffer` instance. ",
"type": "integer",
"name": "kMaxLength",
"meta": {
"added": [
"v3.0.0"
],
"changes": []
},
"desc": "<p>An alias for <a href=\"#buffer_buffer_constants_max_length\"><code>buffer.constants.MAX_LENGTH</code></a>.</p>\n<p>Note that this is a property on the <code>buffer</code> module returned by\n<code>require(&#39;buffer&#39;)</code>, not on the <code>Buffer</code> global or a <code>Buffer</code> instance.</p>\n",
"shortDesc": "The largest size allowed for a single `Buffer` instance."
}
],
"methods": [
{
"textRaw": "buffer.transcode(source, fromEnc, toEnc)",
"type": "method",
"name": "transcode",
"meta": {
"added": [
"v7.1.0"
],
"changes": [
{
"version": "v8.0.0",
"pr-url": "https://github.com/nodejs/node/pull/10236",
"description": "The `source` parameter can now be a `Uint8Array`."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`source` {Buffer|Uint8Array} A `Buffer` or `Uint8Array` instance. ",
"name": "source",
"type": "Buffer|Uint8Array",
"desc": "A `Buffer` or `Uint8Array` instance."
},
{
"textRaw": "`fromEnc` {string} The current encoding. ",
"name": "fromEnc",
"type": "string",
"desc": "The current encoding."
},
{
"textRaw": "`toEnc` {string} To target encoding. ",
"name": "toEnc",
"type": "string",
"desc": "To target encoding."
}
]
},
{
"params": [
{
"name": "source"
},
{
"name": "fromEnc"
},
{
"name": "toEnc"
}
]
}
],
"desc": "<p>Re-encodes the given <code>Buffer</code> or <code>Uint8Array</code> instance from one character\nencoding to another. Returns a new <code>Buffer</code> instance.</p>\n<p>Throws if the <code>fromEnc</code> or <code>toEnc</code> specify invalid character encodings or if\nconversion from <code>fromEnc</code> to <code>toEnc</code> is not permitted.</p>\n<p>The transcoding process will use substitution characters if a given byte\nsequence cannot be adequately represented in the target encoding. For instance:</p>\n<pre><code class=\"lang-js\">const buffer = require(&#39;buffer&#39;);\n\nconst newBuf = buffer.transcode(Buffer.from(&#39;€&#39;), &#39;utf8&#39;, &#39;ascii&#39;);\nconsole.log(newBuf.toString(&#39;ascii&#39;));\n// Prints: &#39;?&#39;\n</code></pre>\n<p>Because the Euro (<code>€</code>) sign is not representable in US-ASCII, it is replaced\nwith <code>?</code> in the transcoded <code>Buffer</code>.</p>\n<p>Note that this is a property on the <code>buffer</code> module returned by\n<code>require(&#39;buffer&#39;)</code>, not on the <code>Buffer</code> global or a <code>Buffer</code> instance.</p>\n"
}
],
"type": "module",
"displayName": "Buffer"
},
{
"textRaw": "Child Process",
"name": "child_process",
"introduced_in": "v0.10.0",
"desc": "<!--lint disable maximum-line-length-->\n<blockquote>\n<p>Stability: 2 - Stable</p>\n</blockquote>\n<p>The <code>child_process</code> module provides the ability to spawn child processes in\na manner that is similar, but not identical, to popen(3). This capability\nis primarily provided by the <a href=\"#child_process_child_process_spawn_command_args_options\"><code>child_process.spawn()</code></a> function:</p>\n<pre><code class=\"lang-js\">const { spawn } = require(&#39;child_process&#39;);\nconst ls = spawn(&#39;ls&#39;, [&#39;-lh&#39;, &#39;/usr&#39;]);\n\nls.stdout.on(&#39;data&#39;, (data) =&gt; {\n console.log(`stdout: ${data}`);\n});\n\nls.stderr.on(&#39;data&#39;, (data) =&gt; {\n console.log(`stderr: ${data}`);\n});\n\nls.on(&#39;close&#39;, (code) =&gt; {\n console.log(`child process exited with code ${code}`);\n});\n</code></pre>\n<p>By default, pipes for <code>stdin</code>, <code>stdout</code>, and <code>stderr</code> are established between\nthe parent Node.js process and the spawned child. These pipes have\nlimited (and platform-specific) capacity. If the child process writes to\nstdout in excess of that limit without the output being captured, the child\nprocess will block waiting for the pipe buffer to accept more data. This is\nidentical to the behavior of pipes in the shell. Use the <code>{ stdio: &#39;ignore&#39; }</code>\noption if the output will not be consumed.</p>\n<p>The <a href=\"#child_process_child_process_spawn_command_args_options\"><code>child_process.spawn()</code></a> method spawns the child process asynchronously,\nwithout blocking the Node.js event loop. The <a href=\"#child_process_child_process_spawnsync_command_args_options\"><code>child_process.spawnSync()</code></a>\nfunction provides equivalent functionality in a synchronous manner that blocks\nthe event loop until the spawned process either exits or is terminated.</p>\n<p>For convenience, the <code>child_process</code> module provides a handful of synchronous\nand asynchronous alternatives to <a href=\"#child_process_child_process_spawn_command_args_options\"><code>child_process.spawn()</code></a> and\n<a href=\"#child_process_child_process_spawnsync_command_args_options\"><code>child_process.spawnSync()</code></a>. <em>Note that each of these alternatives are\nimplemented on top of <a href=\"#child_process_child_process_spawn_command_args_options\"><code>child_process.spawn()</code></a> or <a href=\"#child_process_child_process_spawnsync_command_args_options\"><code>child_process.spawnSync()</code></a>.</em></p>\n<ul>\n<li><a href=\"#child_process_child_process_exec_command_options_callback\"><code>child_process.exec()</code></a>: spawns a shell and runs a command within that shell,\npassing the <code>stdout</code> and <code>stderr</code> to a callback function when complete.</li>\n<li><a
View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment