{
  "type": "module",
  "source": "doc/api/single-executable-applications.md",
  "modules": [
    {
      "textRaw": "Single executable applications",
      "name": "single_executable_applications",
      "introduced_in": "v19.7.0",
      "type": "module",
      "meta": {
        "added": [
          "v19.7.0",
          "v18.16.0"
        ],
        "changes": [
          {
            "version": "v25.5.0",
            "pr-url": "https://github.com/nodejs/node/pull/61167",
            "description": "Added built-in single executable application generation via the CLI flag `--build-sea`."
          },
          {
            "version": "v20.6.0",
            "pr-url": "https://github.com/nodejs/node/pull/46824",
            "description": "Added support for \"useSnapshot\"."
          },
          {
            "version": "v20.6.0",
            "pr-url": "https://github.com/nodejs/node/pull/48191",
            "description": "Added support for \"useCodeCache\"."
          }
        ]
      },
      "stability": 1.1,
      "stabilityText": "Active development",
      "desc": "<p>This feature allows the distribution of a Node.js application conveniently to a\nsystem that does not have Node.js installed.</p>\n<p>Node.js supports the creation of <a href=\"https://github.com/nodejs/single-executable\">single executable applications</a> by allowing\nthe injection of a blob prepared by Node.js, which can contain a bundled script,\ninto the <code>node</code> binary. During start up, the program checks if anything has been\ninjected. If the blob is found, it executes the script in the blob. Otherwise\nNode.js operates as it normally does.</p>\n<p>The single executable application feature supports running a\nsingle embedded script using the <a href=\"modules.html#modules-commonjs-modules\">CommonJS</a> or the <a href=\"esm.html#modules-ecmascript-modules\">ECMAScript Modules</a> module system.</p>\n<p>Users can create a single executable application from their bundled script\nwith the <code>node</code> binary itself and any tool which can inject resources into the\nbinary.</p>\n<ol>\n<li>\n<p>Create a JavaScript file:</p>\n<pre><code class=\"language-bash\">echo 'console.log(`Hello, ${process.argv[2]}!`);' > hello.js\n</code></pre>\n</li>\n<li>\n<p>Create a configuration file building a blob that can be injected into the\nsingle executable application (see\n<a href=\"#1-generating-single-executable-preparation-blobs\">Generating single executable preparation blobs</a> for details):</p>\n<ul>\n<li>On systems other than Windows:</li>\n</ul>\n<pre><code class=\"language-bash\">echo '{ \"main\": \"hello.js\", \"output\": \"sea\" }' > sea-config.json\n</code></pre>\n<ul>\n<li>On Windows:</li>\n</ul>\n<pre><code class=\"language-bash\">echo '{ \"main\": \"hello.js\", \"output\": \"sea.exe\" }' > sea-config.json\n</code></pre>\n<p>The <code>.exe</code> extension is necessary.</p>\n</li>\n<li>\n<p>Generate the target executable:</p>\n<pre><code class=\"language-bash\">node --build-sea sea-config.json\n</code></pre>\n</li>\n<li>\n<p>Sign the binary (macOS and Windows only):</p>\n<ul>\n<li>On macOS:</li>\n</ul>\n<pre><code class=\"language-bash\">codesign --sign - sea\n</code></pre>\n<ul>\n<li>On Windows (optional):</li>\n</ul>\n<p>A certificate needs to be present for this to work. However, the unsigned\nbinary would still be runnable.</p>\n<pre><code class=\"language-powershell\">signtool sign /fd SHA256 sea.exe\n</code></pre>\n</li>\n<li>\n<p>Run the binary:</p>\n<ul>\n<li>On systems other than Windows</li>\n</ul>\n<pre><code class=\"language-console\">$ ./sea world\nHello, world!\n</code></pre>\n<ul>\n<li>On Windows</li>\n</ul>\n<pre><code class=\"language-console\">$ .\\sea.exe world\nHello, world!\n</code></pre>\n</li>\n</ol>",
      "modules": [
        {
          "textRaw": "Generating single executable applications with `--build-sea`",
          "name": "generating_single_executable_applications_with_`--build-sea`",
          "type": "module",
          "desc": "<p>To generate a single executable application directly, the <code>--build-sea</code> flag can be\nused. It takes a path to a configuration file in JSON format. If the path passed to it\nisn't absolute, Node.js will use the path relative to the current working directory.</p>\n<p>The configuration currently reads the following top-level fields:</p>\n<pre><code class=\"language-json\">{\n  \"main\": \"/path/to/bundled/script.js\",\n  \"mainFormat\": \"commonjs\", // Default: \"commonjs\", options: \"commonjs\", \"module\"\n  \"executable\": \"/path/to/node/binary\", // Optional, if not specified, uses the current Node.js binary\n  \"output\": \"/path/to/write/the/generated/executable\",\n  \"disableExperimentalSEAWarning\": true, // Default: false\n  \"useSnapshot\": false,  // Default: false\n  \"useCodeCache\": true, // Default: false\n  \"execArgv\": [\"--no-warnings\", \"--max-old-space-size=4096\"], // Optional\n  \"execArgvExtension\": \"env\", // Default: \"env\", options: \"none\", \"env\", \"cli\"\n  \"assets\": {  // Optional\n    \"a.dat\": \"/path/to/a.dat\",\n    \"b.txt\": \"/path/to/b.txt\"\n  }\n}\n</code></pre>\n<p>If the paths are not absolute, Node.js will use the path relative to the\ncurrent working directory. The version of the Node.js binary used to produce\nthe blob must be the same as the one to which the blob will be injected.</p>\n<p>Note: When generating cross-platform SEAs (e.g., generating a SEA\nfor <code>linux-x64</code> on <code>darwin-arm64</code>), <code>useCodeCache</code> and <code>useSnapshot</code>\nmust be set to false to avoid generating incompatible executables.\nSince code cache and snapshots can only be loaded on the same platform\nwhere they are compiled, the generated executable might crash on startup when\ntrying to load code cache or snapshots built on a different platform.</p>",
          "modules": [
            {
              "textRaw": "Assets",
              "name": "assets",
              "type": "module",
              "desc": "<p>Users can include assets by adding a key-path dictionary to the configuration\nas the <code>assets</code> field. At build time, Node.js would read the assets from the\nspecified paths and bundle them into the preparation blob. In the generated\nexecutable, users can retrieve the assets using the <a href=\"#seagetassetkey-encoding\"><code>sea.getAsset()</code></a> and\n<a href=\"#seagetassetasblobkey-options\"><code>sea.getAssetAsBlob()</code></a> APIs.</p>\n<pre><code class=\"language-json\">{\n  \"main\": \"/path/to/bundled/script.js\",\n  \"output\": \"/path/to/write/the/generated/executable\",\n  \"assets\": {\n    \"a.jpg\": \"/path/to/a.jpg\",\n    \"b.txt\": \"/path/to/b.txt\"\n  }\n}\n</code></pre>\n<p>The single-executable application can access the assets as follows:</p>\n<pre><code class=\"language-cjs\">const { getAsset, getAssetAsBlob, getRawAsset, getAssetKeys } = require('node:sea');\n// Get all asset keys.\nconst keys = getAssetKeys();\nconsole.log(keys); // ['a.jpg', 'b.txt']\n// Returns a copy of the data in an ArrayBuffer.\nconst image = getAsset('a.jpg');\n// Returns a string decoded from the asset as UTF8.\nconst text = getAsset('b.txt', 'utf8');\n// Returns a Blob containing the asset.\nconst blob = getAssetAsBlob('a.jpg');\n// Returns an ArrayBuffer containing the raw asset without copying.\nconst raw = getRawAsset('a.jpg');\n</code></pre>\n<p>See documentation of the <a href=\"#seagetassetkey-encoding\"><code>sea.getAsset()</code></a>, <a href=\"#seagetassetasblobkey-options\"><code>sea.getAssetAsBlob()</code></a>,\n<a href=\"#seagetrawassetkey\"><code>sea.getRawAsset()</code></a> and <a href=\"#seagetassetkeys\"><code>sea.getAssetKeys()</code></a> APIs for more information.</p>",
              "displayName": "Assets"
            },
            {
              "textRaw": "Startup snapshot support",
              "name": "startup_snapshot_support",
              "type": "module",
              "desc": "<p>The <code>useSnapshot</code> field can be used to enable startup snapshot support. In this\ncase, the <code>main</code> script would not be executed when the final executable is launched.\nInstead, it would be run when the single executable application preparation\nblob is generated on the building machine. The generated preparation blob would\nthen include a snapshot capturing the states initialized by the <code>main</code> script.\nThe final executable, with the preparation blob injected, would deserialize\nthe snapshot at run time.</p>\n<p>When <code>useSnapshot</code> is true, the main script must invoke the\n<a href=\"v8.html#v8startupsnapshotsetdeserializemainfunctioncallback-data\"><code>v8.startupSnapshot.setDeserializeMainFunction()</code></a> API to configure code\nthat needs to be run when the final executable is launched by the users.</p>\n<p>The typical pattern for an application to use snapshot in a single executable\napplication is:</p>\n<ol>\n<li>At build time, on the building machine, the main script is run to\ninitialize the heap to a state that's ready to take user input. The script\nshould also configure a main function with\n<a href=\"v8.html#v8startupsnapshotsetdeserializemainfunctioncallback-data\"><code>v8.startupSnapshot.setDeserializeMainFunction()</code></a>. This function will be\ncompiled and serialized into the snapshot, but not invoked at build time.</li>\n<li>At run time, the main function will be run on top of the deserialized heap\non the user machine to process user input and generate output.</li>\n</ol>\n<p>The general constraints of the startup snapshot scripts also apply to the main\nscript when it's used to build snapshot for the single executable application,\nand the main script can use the <a href=\"v8.html#startup-snapshot-api\"><code>v8.startupSnapshot</code> API</a> to adapt to\nthese constraints. See\n<a href=\"cli.html#--build-snapshot\">documentation about startup snapshot support in Node.js</a>.</p>",
              "displayName": "Startup snapshot support"
            },
            {
              "textRaw": "V8 code cache support",
              "name": "v8_code_cache_support",
              "type": "module",
              "desc": "<p>When <code>useCodeCache</code> is set to <code>true</code> in the configuration, during the generation\nof the single executable preparation blob, Node.js will compile the <code>main</code>\nscript to generate the V8 code cache. The generated code cache would be part of\nthe preparation blob and get injected into the final executable. When the single\nexecutable application is launched, instead of compiling the <code>main</code> script from\nscratch, Node.js would use the code cache to speed up the compilation, then\nexecute the script, which would improve the startup performance.</p>\n<p><strong>Note:</strong> <code>import()</code> does not work when <code>useCodeCache</code> is <code>true</code>.</p>",
              "displayName": "V8 code cache support"
            },
            {
              "textRaw": "Execution arguments",
              "name": "execution_arguments",
              "type": "module",
              "desc": "<p>The <code>execArgv</code> field can be used to specify Node.js-specific\narguments that will be automatically applied when the single\nexecutable application starts. This allows application developers\nto configure Node.js runtime options without requiring end users\nto be aware of these flags.</p>\n<p>For example, the following configuration:</p>\n<pre><code class=\"language-json\">{\n  \"main\": \"/path/to/bundled/script.js\",\n  \"output\": \"/path/to/write/the/generated/executable\",\n  \"execArgv\": [\"--no-warnings\", \"--max-old-space-size=2048\"]\n}\n</code></pre>\n<p>will instruct the SEA to be launched with the <code>--no-warnings</code> and\n<code>--max-old-space-size=2048</code> flags. In the scripts embedded in the executable, these flags\ncan be accessed using the <code>process.execArgv</code> property:</p>\n<pre><code class=\"language-js\">// If the executable is launched with `sea user-arg1 user-arg2`\nconsole.log(process.execArgv);\n// Prints: ['--no-warnings', '--max-old-space-size=2048']\nconsole.log(process.argv);\n// Prints ['/path/to/sea', 'path/to/sea', 'user-arg1', 'user-arg2']\n</code></pre>\n<p>The user-provided arguments are in the <code>process.argv</code> array starting from index 2,\nsimilar to what would happen if the application is started with:</p>\n<pre><code class=\"language-console\">node --no-warnings --max-old-space-size=2048 /path/to/bundled/script.js user-arg1 user-arg2\n</code></pre>",
              "displayName": "Execution arguments"
            },
            {
              "textRaw": "Execution argument extension",
              "name": "execution_argument_extension",
              "type": "module",
              "desc": "<p>The <code>execArgvExtension</code> field controls how additional execution arguments can be\nprovided beyond those specified in the <code>execArgv</code> field. It accepts one of three string values:</p>\n<ul>\n<li><code>\"none\"</code>: No extension is allowed. Only the arguments specified in <code>execArgv</code> will be used,\nand the <code>NODE_OPTIONS</code> environment variable will be ignored.</li>\n<li><code>\"env\"</code>: <em>(Default)</em> The <code>NODE_OPTIONS</code> environment variable can extend the execution arguments.\nThis is the default behavior to maintain backward compatibility.</li>\n<li><code>\"cli\"</code>: The executable can be launched with <code>--node-options=\"--flag1 --flag2\"</code>, and those flags\nwill be parsed as execution arguments for Node.js instead of being passed to the user script.\nThis allows using arguments that are not supported by the <code>NODE_OPTIONS</code> environment variable.</li>\n</ul>\n<p>For example, with <code>\"execArgvExtension\": \"cli\"</code>:</p>\n<pre><code class=\"language-json\">{\n  \"main\": \"/path/to/bundled/script.js\",\n  \"output\": \"/path/to/write/the/generated/executable\",\n  \"execArgv\": [\"--no-warnings\"],\n  \"execArgvExtension\": \"cli\"\n}\n</code></pre>\n<p>The executable can be launched as:</p>\n<pre><code class=\"language-console\">./my-sea --node-options=\"--trace-exit\" user-arg1 user-arg2\n</code></pre>\n<p>This would be equivalent to running:</p>\n<pre><code class=\"language-console\">node --no-warnings --trace-exit /path/to/bundled/script.js user-arg1 user-arg2\n</code></pre>",
              "displayName": "Execution argument extension"
            }
          ],
          "displayName": "Generating single executable applications with `--build-sea`"
        },
        {
          "textRaw": "Single-executable application API",
          "name": "single-executable_application_api",
          "type": "module",
          "desc": "<p>The <code>node:sea</code> builtin allows interaction with the single-executable application\nfrom the JavaScript main script embedded into the executable.</p>",
          "methods": [
            {
              "textRaw": "`sea.isSea()`",
              "name": "isSea",
              "type": "method",
              "meta": {
                "added": [
                  "v21.7.0",
                  "v20.12.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [],
                  "return": {
                    "textRaw": "Returns: {boolean} Whether this script is running inside a single-executable application.",
                    "name": "return",
                    "type": "boolean",
                    "desc": "Whether this script is running inside a single-executable application."
                  }
                }
              ]
            },
            {
              "textRaw": "`sea.getAsset(key[, encoding])`",
              "name": "getAsset",
              "type": "method",
              "meta": {
                "added": [
                  "v21.7.0",
                  "v20.12.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`key` {string} the key for the asset in the dictionary specified by the `assets` field in the single-executable application configuration.",
                      "name": "key",
                      "type": "string",
                      "desc": "the key for the asset in the dictionary specified by the `assets` field in the single-executable application configuration."
                    },
                    {
                      "textRaw": "`encoding` {string} If specified, the asset will be decoded as a string. Any encoding supported by the `TextDecoder` is accepted. If unspecified, an `ArrayBuffer` containing a copy of the asset would be returned instead.",
                      "name": "encoding",
                      "type": "string",
                      "desc": "If specified, the asset will be decoded as a string. Any encoding supported by the `TextDecoder` is accepted. If unspecified, an `ArrayBuffer` containing a copy of the asset would be returned instead.",
                      "optional": true
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {string|ArrayBuffer}",
                    "name": "return",
                    "type": "string|ArrayBuffer"
                  }
                }
              ],
              "desc": "<p>This method can be used to retrieve the assets configured to be bundled into the\nsingle-executable application at build time.\nAn error is thrown when no matching asset can be found.</p>"
            },
            {
              "textRaw": "`sea.getAssetAsBlob(key[, options])`",
              "name": "getAssetAsBlob",
              "type": "method",
              "meta": {
                "added": [
                  "v21.7.0",
                  "v20.12.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`key` {string} the key for the asset in the dictionary specified by the `assets` field in the single-executable application configuration.",
                      "name": "key",
                      "type": "string",
                      "desc": "the key for the asset in the dictionary specified by the `assets` field in the single-executable application configuration."
                    },
                    {
                      "textRaw": "`options` {Object}",
                      "name": "options",
                      "type": "Object",
                      "options": [
                        {
                          "textRaw": "`type` {string} An optional mime type for the blob.",
                          "name": "type",
                          "type": "string",
                          "desc": "An optional mime type for the blob."
                        }
                      ],
                      "optional": true
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {Blob}",
                    "name": "return",
                    "type": "Blob"
                  }
                }
              ],
              "desc": "<p>Similar to <a href=\"#seagetassetkey-encoding\"><code>sea.getAsset()</code></a>, but returns the result in a <a href=\"buffer.html#class-blob\"><code>&#x3C;Blob></code></a>.\nAn error is thrown when no matching asset can be found.</p>"
            },
            {
              "textRaw": "`sea.getRawAsset(key)`",
              "name": "getRawAsset",
              "type": "method",
              "meta": {
                "added": [
                  "v21.7.0",
                  "v20.12.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`key` {string} the key for the asset in the dictionary specified by the `assets` field in the single-executable application configuration.",
                      "name": "key",
                      "type": "string",
                      "desc": "the key for the asset in the dictionary specified by the `assets` field in the single-executable application configuration."
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {ArrayBuffer}",
                    "name": "return",
                    "type": "ArrayBuffer"
                  }
                }
              ],
              "desc": "<p>This method can be used to retrieve the assets configured to be bundled into the\nsingle-executable application at build time.\nAn error is thrown when no matching asset can be found.</p>\n<p>Unlike <code>sea.getAsset()</code> or <code>sea.getAssetAsBlob()</code>, this method does not\nreturn a copy. Instead, it returns the raw asset bundled inside the executable.</p>\n<p>For now, users should avoid writing to the returned array buffer. If the\ninjected section is not marked as writable or not aligned properly,\nwrites to the returned array buffer is likely to result in a crash.</p>"
            },
            {
              "textRaw": "`sea.getAssetKeys()`",
              "name": "getAssetKeys",
              "type": "method",
              "meta": {
                "added": [
                  "v24.8.0",
                  "v22.20.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [],
                  "return": {
                    "textRaw": "Returns {string}[] An array containing all the keys of the assets embedded in the executable. If no assets are embedded, returns an empty array.",
                    "name": "return",
                    "type": "string",
                    "desc": "[] An array containing all the keys of the assets embedded in the executable. If no assets are embedded, returns an empty array."
                  }
                }
              ],
              "desc": "<p>This method can be used to retrieve an array of all the keys of assets\nembedded into the single-executable application.\nAn error is thrown when not running inside a single-executable application.</p>"
            }
          ],
          "displayName": "Single-executable application API"
        },
        {
          "textRaw": "In the injected main script",
          "name": "in_the_injected_main_script",
          "type": "module",
          "modules": [
            {
              "textRaw": "Module format of the injected main script",
              "name": "module_format_of_the_injected_main_script",
              "type": "module",
              "desc": "<p>To specify how Node.js should interpret the injected main script, use the\n<code>mainFormat</code> field in the single-executable application configuration.\nThe accepted values are:</p>\n<ul>\n<li><code>\"commonjs\"</code>: The injected main script is treated as a CommonJS module.</li>\n<li><code>\"module\"</code>: The injected main script is treated as an ECMAScript module.</li>\n</ul>\n<p>If the <code>mainFormat</code> field is not specified, it defaults to <code>\"commonjs\"</code>.</p>\n<p>Currently, <code>\"mainFormat\": \"module\"</code> cannot be used together with <code>\"useSnapshot\"</code>.</p>",
              "displayName": "Module format of the injected main script"
            },
            {
              "textRaw": "Module loading in the injected main script",
              "name": "module_loading_in_the_injected_main_script",
              "type": "module",
              "desc": "<p>In the injected main script, module loading does not read from the file system.\nBy default, both <code>require()</code> and <code>import</code> statements would only be able to load\nthe built-in modules. Attempting to load a module that can only be found in the\nfile system will throw an error.</p>\n<p>Users can bundle their application into a standalone JavaScript file to inject\ninto the executable. This also ensures a more deterministic dependency graph.</p>\n<p>To load modules from the file system in the injected main script, users can\ncreate a <code>require</code> function that can load from the file system using\n<code>module.createRequire()</code>. For example, in a CommonJS entry point:</p>\n<pre><code class=\"language-js\">const { createRequire } = require('node:module');\nrequire = createRequire(__filename);\n</code></pre>",
              "displayName": "Module loading in the injected main script"
            },
            {
              "textRaw": "`require()` in the injected main script",
              "name": "`require()`_in_the_injected_main_script",
              "type": "module",
              "desc": "<p><code>require()</code> in the injected main script is not the same as the <a href=\"modules.html#requireid\"><code>require()</code></a>\navailable to modules that are not injected.\nCurrently, it does not have any of the properties that non-injected\n<a href=\"modules.html#requireid\"><code>require()</code></a> has except <a href=\"modules.html#accessing-the-main-module\"><code>require.main</code></a>.</p>",
              "displayName": "`require()` in the injected main script"
            },
            {
              "textRaw": "`__filename` and `module.filename` in the injected main script",
              "name": "`__filename`_and_`module.filename`_in_the_injected_main_script",
              "type": "module",
              "desc": "<p>The values of <code>__filename</code> and <code>module.filename</code> in the injected main script\nare equal to <a href=\"process.html#processexecpath\"><code>process.execPath</code></a>.</p>",
              "displayName": "`__filename` and `module.filename` in the injected main script"
            },
            {
              "textRaw": "`__dirname` in the injected main script",
              "name": "`__dirname`_in_the_injected_main_script",
              "type": "module",
              "desc": "<p>The value of <code>__dirname</code> in the injected main script is equal to the directory\nname of <a href=\"process.html#processexecpath\"><code>process.execPath</code></a>.</p>",
              "displayName": "`__dirname` in the injected main script"
            },
            {
              "textRaw": "`import.meta` in the injected main script",
              "name": "`import.meta`_in_the_injected_main_script",
              "type": "module",
              "desc": "<p>When using <code>\"mainFormat\": \"module\"</code>, <code>import.meta</code> is available in the\ninjected main script with the following properties:</p>\n<ul>\n<li><code>import.meta.url</code>: A <code>file:</code> URL corresponding to <a href=\"process.html#processexecpath\"><code>process.execPath</code></a>.</li>\n<li><code>import.meta.filename</code>: Equal to <a href=\"process.html#processexecpath\"><code>process.execPath</code></a>.</li>\n<li><code>import.meta.dirname</code>: The directory name of <a href=\"process.html#processexecpath\"><code>process.execPath</code></a>.</li>\n<li><code>import.meta.main</code>: <code>true</code>.</li>\n</ul>\n<p><code>import.meta.resolve</code> is currently not supported.</p>",
              "displayName": "`import.meta` in the injected main script"
            },
            {
              "textRaw": "`import()` in the injected main script",
              "name": "`import()`_in_the_injected_main_script",
              "type": "module",
              "desc": "<p>When using <code>\"mainFormat\": \"module\"</code>, <code>import()</code> can be used to dynamically\nload built-in modules. Attempting to use <code>import()</code> to load modules from\nthe file system will throw an error.</p>",
              "displayName": "`import()` in the injected main script"
            },
            {
              "textRaw": "Using native addons in the injected main script",
              "name": "using_native_addons_in_the_injected_main_script",
              "type": "module",
              "desc": "<p>Native addons can be bundled as assets into the single-executable application\nby specifying them in the <code>assets</code> field of the configuration file used to\ngenerate the single-executable application preparation blob.\nThe addon can then be loaded in the injected main script by writing the asset\nto a temporary file and loading it with <code>process.dlopen()</code>.</p>\n<pre><code class=\"language-json\">{\n  \"main\": \"/path/to/bundled/script.js\",\n  \"output\": \"/path/to/write/the/generated/executable\",\n  \"assets\": {\n    \"myaddon.node\": \"/path/to/myaddon/build/Release/myaddon.node\"\n  }\n}\n</code></pre>\n<pre><code class=\"language-js\">// script.js\nconst fs = require('node:fs');\nconst os = require('node:os');\nconst path = require('node:path');\nconst { getRawAsset } = require('node:sea');\nconst addonPath = path.join(os.tmpdir(), 'myaddon.node');\nfs.writeFileSync(addonPath, new Uint8Array(getRawAsset('myaddon.node')));\nconst myaddon = { exports: {} };\nprocess.dlopen(myaddon, addonPath);\nconsole.log(myaddon.exports);\nfs.rmSync(addonPath);\n</code></pre>\n<p>Known caveat: if the single-executable application is produced by postject running on a Linux arm64 docker container,\n<a href=\"https://github.com/nodejs/postject/issues/105\">the produced ELF binary does not have the correct hash table to load the addons</a> and\nwill crash on <code>process.dlopen()</code>. Build the single-executable application on other platforms, or at least on\na non-container Linux arm64 environment to work around this issue.</p>",
              "displayName": "Using native addons in the injected main script"
            }
          ],
          "displayName": "In the injected main script"
        },
        {
          "textRaw": "Notes",
          "name": "notes",
          "type": "module",
          "modules": [
            {
              "textRaw": "Single executable application creation process",
              "name": "single_executable_application_creation_process",
              "type": "module",
              "desc": "<p>The process documented here is subject to change.</p>",
              "modules": [
                {
                  "textRaw": "1. Generating single executable preparation blobs",
                  "name": "1._generating_single_executable_preparation_blobs",
                  "type": "module",
                  "desc": "<p>To build a single executable application, Node.js would first generate a blob\nthat contains all the necessary information to run the bundled script.\nWhen using <code>--build-sea</code>, this step is done internally along with the injection.</p>",
                  "modules": [
                    {
                      "textRaw": "Dumping the preparation blob to disk",
                      "name": "dumping_the_preparation_blob_to_disk",
                      "type": "module",
                      "desc": "<p>Before <code>--build-sea</code> was introduced, an older workflow was introduced to write the\npreparation blob to disk for injection by external tools. This can still\nbe used for verification purposes.</p>\n<p>To dump the preparation blob to disk for verification, use <code>--experimental-sea-config</code>.\nThis writes a file that can be injected into a Node.js binary using tools like <a href=\"https://github.com/nodejs/postject\">postject</a>.</p>\n<p>The configuration is similar to that of <code>--build-sea</code>, except that the\n<code>output</code> field specifies the path to write the generated blob file instead of\nthe final executable.</p>\n<pre><code class=\"language-json\">{\n  \"main\": \"/path/to/bundled/script.js\",\n  // Instead of the final executable, this is the path to write the blob.\n  \"output\": \"/path/to/write/the/generated/blob.blob\"\n}\n</code></pre>",
                      "displayName": "Dumping the preparation blob to disk"
                    }
                  ],
                  "displayName": "1. Generating single executable preparation blobs"
                },
                {
                  "textRaw": "2. Injecting the preparation blob into the `node` binary",
                  "name": "2._injecting_the_preparation_blob_into_the_`node`_binary",
                  "type": "module",
                  "desc": "<p>To complete the creation of a single executable application, the generated blob\nneeds to be injected into a copy of the <code>node</code> binary, as documented below.</p>\n<p>When using <code>--build-sea</code>, this step is done internally along with the blob generation.</p>\n<ul>\n<li>If the <code>node</code> binary is a <a href=\"https://en.wikipedia.org/wiki/Portable_Executable\">PE</a> file, the blob should be injected as a resource\nnamed <code>NODE_SEA_BLOB</code>.</li>\n<li>If the <code>node</code> binary is a <a href=\"https://en.wikipedia.org/wiki/Mach-O\">Mach-O</a> file, the blob should be injected as a section\nnamed <code>NODE_SEA_BLOB</code> in the <code>NODE_SEA</code> segment.</li>\n<li>If the <code>node</code> binary is an <a href=\"https://en.wikipedia.org/wiki/Executable_and_Linkable_Format\">ELF</a> file, the blob should be injected as a note\nnamed <code>NODE_SEA_BLOB</code>.</li>\n</ul>\n<p>Then, the SEA building process searches the binary for the\n<code>NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2:0</code> <a href=\"https://www.electronjs.org/docs/latest/tutorial/fuses\">fuse</a> string and flip the\nlast character to <code>1</code> to indicate that a resource has been injected.</p>",
                  "modules": [
                    {
                      "textRaw": "Injecting the preparation blob manually",
                      "name": "injecting_the_preparation_blob_manually",
                      "type": "module",
                      "desc": "<p>Before <code>--build-sea</code> was introduced, an older workflow was introduced to allow\nexternal tools to inject the generated blob into a copy of the <code>node</code> binary.</p>\n<p>For example, with <a href=\"https://github.com/nodejs/postject\">postject</a>:</p>\n<ol>\n<li>\n<p>Create a copy of the <code>node</code> executable and name it according to your needs:</p>\n<ul>\n<li>On systems other than Windows:</li>\n</ul>\n<pre><code class=\"language-bash\">cp $(command -v node) hello\n</code></pre>\n<ul>\n<li>On Windows:</li>\n</ul>\n<pre><code class=\"language-text\">node -e \"require('fs').copyFileSync(process.execPath, 'hello.exe')\"\n</code></pre>\n<p>The <code>.exe</code> extension is necessary.</p>\n</li>\n<li>\n<p>Remove the signature of the binary (macOS and Windows only):</p>\n<ul>\n<li>On macOS:</li>\n</ul>\n<pre><code class=\"language-bash\">codesign --remove-signature hello\n</code></pre>\n<ul>\n<li>On Windows (optional):</li>\n</ul>\n<p><a href=\"https://learn.microsoft.com/en-us/windows/win32/seccrypto/signtool\">signtool</a> can be used from the installed <a href=\"https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/\">Windows SDK</a>. If this step is\nskipped, ignore any signature-related warning from postject.</p>\n<pre><code class=\"language-powershell\">signtool remove /s hello.exe\n</code></pre>\n</li>\n<li>\n<p>Inject the blob into the copied binary by running <code>postject</code> with\nthe following options:</p>\n<ul>\n<li><code>hello</code> / <code>hello.exe</code> - The name of the copy of the <code>node</code> executable\ncreated in step 4.</li>\n<li><code>NODE_SEA_BLOB</code> - The name of the resource / note / section in the binary\nwhere the contents of the blob will be stored.</li>\n<li><code>sea-prep.blob</code> - The name of the blob created in step 1.</li>\n<li><code>--sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2</code> - The\n<a href=\"https://www.electronjs.org/docs/latest/tutorial/fuses\">fuse</a> used by the Node.js project to detect if a file has been injected.</li>\n<li><code>--macho-segment-name NODE_SEA</code> (only needed on macOS) - The name of the\nsegment in the binary where the contents of the blob will be\nstored.</li>\n</ul>\n<p>To summarize, here is the required command for each platform:</p>\n<ul>\n<li>\n<p>On Linux:</p>\n<pre><code class=\"language-bash\">npx postject hello NODE_SEA_BLOB sea-prep.blob \\\n    --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2\n</code></pre>\n</li>\n<li>\n<p>On Windows - PowerShell:</p>\n<pre><code class=\"language-powershell\">npx postject hello.exe NODE_SEA_BLOB sea-prep.blob `\n    --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2\n</code></pre>\n</li>\n<li>\n<p>On Windows - Command Prompt:</p>\n<pre><code class=\"language-text\">npx postject hello.exe NODE_SEA_BLOB sea-prep.blob ^\n    --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2\n</code></pre>\n</li>\n<li>\n<p>On macOS:</p>\n<pre><code class=\"language-bash\">npx postject hello NODE_SEA_BLOB sea-prep.blob \\\n    --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 \\\n    --macho-segment-name NODE_SEA\n</code></pre>\n</li>\n</ul>\n</li>\n</ol>",
                      "displayName": "Injecting the preparation blob manually"
                    }
                  ],
                  "displayName": "2. Injecting the preparation blob into the `node` binary"
                }
              ],
              "displayName": "Single executable application creation process"
            },
            {
              "textRaw": "Platform support",
              "name": "platform_support",
              "type": "module",
              "desc": "<p>Single-executable support is tested regularly on CI only on the following\nplatforms:</p>\n<ul>\n<li>Windows</li>\n<li>macOS (arm64 only; x64 is not currently supported and is skipped in the\ntests)</li>\n<li>Linux (all distributions <a href=\"https://github.com/nodejs/node/blob/main/BUILDING.md#platform-list\">supported by Node.js</a> except Alpine and all\narchitectures <a href=\"https://github.com/nodejs/node/blob/main/BUILDING.md#platform-list\">supported by Node.js</a> except s390x)</li>\n</ul>\n<p>This is due to a lack of better tools to generate single-executables that can be\nused to test this feature on other platforms.</p>\n<p>Suggestions for other resource injection tools/workflows are welcomed. Please\nstart a discussion at <a href=\"https://github.com/nodejs/single-executable/discussions\">https://github.com/nodejs/single-executable/discussions</a>\nto help us document them.</p>",
              "displayName": "Platform support"
            }
          ],
          "displayName": "Notes"
        }
      ],
      "displayName": "Single executable applications"
    }
  ]
}