{"$schema":"https://doc-kit.nodejs.org/schemas/api-doc/1.0.0.json","id":"single-executable-applications","path":"/single-executable-applications","type":"module","module":"single-executable-applications","title":"Single executable applications","introducedIn":"v19.7.0","sourceLink":{"path":"src/node_sea.cc","url":"https://github.com/nodejs/node/blob/HEAD/src/node_sea.cc"},"stability":{"index":"1.1","description":"Active development"},"added":["v19.7.0","v18.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v25.5.0"],"prUrl":"https://github.com/nodejs/node/pull/61167","commit":null,"description":"Added built-in single executable application generation via the CLI flag `--build-sea`."},{"versions":["v20.6.0"],"prUrl":"https://github.com/nodejs/node/pull/46824","commit":null,"description":"Added support for \"useSnapshot\"."},{"versions":["v20.6.0"],"prUrl":"https://github.com/nodejs/node/pull/48191","commit":null,"description":"Added support for \"useCodeCache\"."}],"description":"This feature allows the distribution of a Node.js application conveniently to a\nsystem that does not have Node.js installed.\n\nNode.js supports the creation of [single executable applications](https://github.com/nodejs/single-executable) by allowing\nthe injection of a blob prepared by Node.js, which can contain a bundled script,\ninto the `node` 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.\n\nThe single executable application feature supports running a\nsingle embedded script using the [CommonJS](modules.html#modules-commonjs-modules) or the [ECMAScript Modules](esm.html#modules-ecmascript-modules) module system.\n\nUsers can create a single executable application from their bundled script\nwith the `node` binary itself and any tool which can inject resources into the\nbinary.\n\n1. Create a JavaScript file:\n   ```bash\n   echo 'console.log(`Hello, ${process.argv[2]}!`);' > hello.js\n   ```\n\n2. Create a configuration file building a blob that can be injected into the\n   single executable application (see\n   [Generating single executable preparation blobs](#1-generating-single-executable-preparation-blobs) for details):\n\n   * On systems other than Windows:\n\n   ```bash\n   echo '{ \"main\": \"hello.js\", \"output\": \"sea\" }' > sea-config.json\n   ```\n\n   * On Windows:\n\n   ```bash\n   echo '{ \"main\": \"hello.js\", \"output\": \"sea.exe\" }' > sea-config.json\n   ```\n\n   The `.exe` extension is necessary.\n\n3. Generate the target executable:\n   ```bash\n   node --build-sea sea-config.json\n   ```\n\n4. Sign the binary (macOS and Windows only):\n\n   * On macOS:\n\n   ```bash\n   codesign --sign - sea\n   ```\n\n   * On Windows (optional):\n\n   A certificate needs to be present for this to work. However, the unsigned\n   binary would still be runnable.\n\n   ```powershell\n   signtool sign /fd SHA256 sea.exe\n   ```\n\n5. Run the binary:\n\n   * On systems other than Windows\n\n   ```console\n   $ ./sea world\n   Hello, world!\n   ```\n\n   * On Windows\n\n   ```console\n   $ .\\sea.exe world\n   Hello, world!\n   ```","summary":"This feature allows the distribution of a Node.js application conveniently to a system that does not have Node.js installed.","examples":[{"language":"bash","displayName":null,"code":"echo 'console.log(`Hello, ${process.argv[2]}!`);' > hello.js"},{"language":"bash","displayName":null,"code":"echo '{ \"main\": \"hello.js\", \"output\": \"sea\" }' > sea-config.json"},{"language":"bash","displayName":null,"code":"echo '{ \"main\": \"hello.js\", \"output\": \"sea.exe\" }' > sea-config.json"},{"language":"bash","displayName":null,"code":"node --build-sea sea-config.json"},{"language":"bash","displayName":null,"code":"codesign --sign - sea"},{"language":"powershell","displayName":null,"code":"signtool sign /fd SHA256 sea.exe"},{"language":"console","displayName":null,"code":"$ ./sea world\nHello, world!"},{"language":"console","displayName":null,"code":"$ .\\sea.exe world\nHello, world!"}],"children":[{"kind":"section","id":"-build-sea","name":"Generating single executable applications with --build-sea","title":"Generating single executable applications with `--build-sea`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"To generate a single executable application directly, the `--build-sea` 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.\n\nThe configuration currently reads the following top-level fields:\n\n```json\n{\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```\n\nIf 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.\n\nNote: When generating cross-platform SEAs (e.g., generating a SEA\nfor `linux-x64` on `darwin-arm64`), `useCodeCache` and `useSnapshot`\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.","summary":"To generate a single executable application directly, the `--build-sea` flag can be used. It takes a path to a configuration file in JSON format. If the path passed to it isn't absolute, Node.js will use the path relative to the current working directory.","examples":[{"language":"json","displayName":null,"code":"{\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}"}],"children":[{"kind":"section","id":"assets","name":"Assets","title":"Assets","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Users can include assets by adding a key-path dictionary to the configuration\nas the `assets` 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 [`sea.getAsset()`](#seagetassetkey-encoding) and\n[`sea.getAssetAsBlob()`](#seagetassetasblobkey-options) APIs.\n\n```json\n{\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```\n\nThe single-executable application can access the assets as follows:\n\n```cjs\nconst { 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```\n\nSee documentation of the [`sea.getAsset()`](#seagetassetkey-encoding), [`sea.getAssetAsBlob()`](#seagetassetasblobkey-options),\n[`sea.getRawAsset()`](#seagetrawassetkey) and [`sea.getAssetKeys()`](#seagetassetkeys) APIs for more information.","summary":"Users can include assets by adding a key-path dictionary to the configuration as the `assets` field. At build time, Node.js would read the assets from the specified paths and bundle them into the preparation blob. In the generated executable, users can retrieve the assets using the `sea.getAsset()` and `sea.getAssetAsBlob()` APIs.","examples":[{"language":"json","displayName":null,"code":"{\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}"},{"language":"cjs","displayName":null,"code":"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');"}],"children":[]},{"kind":"section","id":"startup-snapshot-support","name":"Startup snapshot support","title":"Startup snapshot support","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `useSnapshot` field can be used to enable startup snapshot support. In this\ncase, the `main` 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 `main` script.\nThe final executable, with the preparation blob injected, would deserialize\nthe snapshot at run time.\n\nWhen `useSnapshot` is true, the main script must invoke the\n[`v8.startupSnapshot.setDeserializeMainFunction()`](v8.html#v8startupsnapshotsetdeserializemainfunctioncallback-data) API to configure code\nthat needs to be run when the final executable is launched by the users.\n\nThe typical pattern for an application to use snapshot in a single executable\napplication is:\n\n1. At build time, on the building machine, the main script is run to\n   initialize the heap to a state that's ready to take user input. The script\n   should also configure a main function with\n   [`v8.startupSnapshot.setDeserializeMainFunction()`](v8.html#v8startupsnapshotsetdeserializemainfunctioncallback-data). This function will be\n   compiled and serialized into the snapshot, but not invoked at build time.\n2. At run time, the main function will be run on top of the deserialized heap\n   on the user machine to process user input and generate output.\n\nThe 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 [`v8.startupSnapshot` API](v8.html#startup-snapshot-api) to adapt to\nthese constraints. See\n[documentation about startup snapshot support in Node.js](cli.html#--build-snapshot).","summary":"The `useSnapshot` field can be used to enable startup snapshot support. In this case, the `main` script would not be executed when the final executable is launched. Instead, it would be run when the single executable application preparation blob is generated on the building machine. The generated preparation blob would then include a snapshot capturing the states initialized by the `main` script. The final executable, with the preparation blob injected, would deserialize the snapshot at run time.","examples":[],"children":[]},{"kind":"section","id":"v8-code-cache-support","name":"V8 code cache support","title":"V8 code cache support","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"When `useCodeCache` is set to `true` in the configuration, during the generation\nof the single executable preparation blob, Node.js will compile the `main`\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 `main` 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.\n\n**Note:** `import()` does not work when `useCodeCache` is `true`.","summary":"When `useCodeCache` is set to `true` in the configuration, during the generation of the single executable preparation blob, Node.js will compile the `main` script to generate the V8 code cache. The generated code cache would be part of the preparation blob and get injected into the final executable. When the single executable application is launched, instead of compiling the `main` script from scratch, Node.js would use the code cache to speed up the compilation, then execute the script, which would improve the startup performance.","examples":[],"children":[]},{"kind":"section","id":"execution-arguments","name":"Execution arguments","title":"Execution arguments","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `execArgv` 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.\n\nFor example, the following configuration:\n\n```json\n{\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```\n\nwill instruct the SEA to be launched with the `--no-warnings` and\n`--max-old-space-size=2048` flags. In the scripts embedded in the executable, these flags\ncan be accessed using the `process.execArgv` property:\n\n```js\n// 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```\n\nThe user-provided arguments are in the `process.argv` array starting from index 2,\nsimilar to what would happen if the application is started with:\n\n```console\nnode --no-warnings --max-old-space-size=2048 /path/to/bundled/script.js user-arg1 user-arg2\n```","summary":"The `execArgv` field can be used to specify Node.js-specific arguments that will be automatically applied when the single executable application starts. This allows application developers to configure Node.js runtime options without requiring end users to be aware of these flags.","examples":[{"language":"json","displayName":null,"code":"{\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}"},{"language":"js","displayName":null,"code":"// 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']"},{"language":"console","displayName":null,"code":"node --no-warnings --max-old-space-size=2048 /path/to/bundled/script.js user-arg1 user-arg2"}],"children":[]},{"kind":"section","id":"execution-argument-extension","name":"Execution argument extension","title":"Execution argument extension","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `execArgvExtension` field controls how additional execution arguments can be\nprovided beyond those specified in the `execArgv` field. It accepts one of three string values:\n\n* `\"none\"`: No extension is allowed. Only the arguments specified in `execArgv` will be used,\n  and the `NODE_OPTIONS` environment variable will be ignored.\n* `\"env\"`: *(Default)* The `NODE_OPTIONS` environment variable can extend the execution arguments.\n  This is the default behavior to maintain backward compatibility.\n* `\"cli\"`: The executable can be launched with `--node-options=\"--flag1 --flag2\"`, and those flags\n  will be parsed as execution arguments for Node.js instead of being passed to the user script.\n  This allows using arguments that are not supported by the `NODE_OPTIONS` environment variable.\n\nFor example, with `\"execArgvExtension\": \"cli\"`:\n\n```json\n{\n  \"main\": \"/path/to/bundled/script.js\",\n  \"output\": \"/path/to/write/the/generated/executable\",\n  \"execArgv\": [\"--no-warnings\"],\n  \"execArgvExtension\": \"cli\"\n}\n```\n\nThe executable can be launched as:\n\n```console\n./my-sea --node-options=\"--trace-exit\" user-arg1 user-arg2\n```\n\nThis would be equivalent to running:\n\n```console\nnode --no-warnings --trace-exit /path/to/bundled/script.js user-arg1 user-arg2\n```","summary":"The `execArgvExtension` field controls how additional execution arguments can be provided beyond those specified in the `execArgv` field. It accepts one of three string values:","examples":[{"language":"json","displayName":null,"code":"{\n  \"main\": \"/path/to/bundled/script.js\",\n  \"output\": \"/path/to/write/the/generated/executable\",\n  \"execArgv\": [\"--no-warnings\"],\n  \"execArgvExtension\": \"cli\"\n}"},{"language":"console","displayName":null,"code":"./my-sea --node-options=\"--trace-exit\" user-arg1 user-arg2"},{"language":"console","displayName":null,"code":"node --no-warnings --trace-exit /path/to/bundled/script.js user-arg1 user-arg2"}],"children":[]}]},{"kind":"section","id":"single-executable-application-api","name":"Single-executable application API","title":"Single-executable application API","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `node:sea` builtin allows interaction with the single-executable application\nfrom the JavaScript main script embedded into the executable.","summary":"The `node:sea` builtin allows interaction with the single-executable application from the JavaScript main script embedded into the executable.","examples":[],"children":[{"kind":"method","id":"seaissea","name":"isSea","title":"`sea.isSea()`","scope":"module","overloadOf":null,"stability":null,"added":["v21.7.0","v20.12.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Whether this script is running inside a single-executable\napplication."}},"description":"","summary":"","examples":[],"children":[]},{"kind":"method","id":"seagetassetkey-encoding","name":"getAsset","title":"`sea.getAsset(key[, encoding])`","scope":"module","overloadOf":null,"stability":null,"added":["v21.7.0","v20.12.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"key","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"the key for the asset in the dictionary specified by the\n`assets` field in the single-executable application configuration.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"encoding","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"If specified, the asset will be decoded as\na string. Any encoding supported by the `TextDecoder` is accepted.\nIf unspecified, an `ArrayBuffer` containing a copy of the asset would be\nreturned instead.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"string | ArrayBuffer","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"ArrayBuffer","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer","start":9,"end":20}]},"description":""}},"description":"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.","summary":"This method can be used to retrieve the assets configured to be bundled into the single-executable application at build time. An error is thrown when no matching asset can be found.","examples":[],"children":[]},{"kind":"method","id":"seagetassetasblobkey-options","name":"getAssetAsBlob","title":"`sea.getAssetAsBlob(key[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v21.7.0","v20.12.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"key","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"the key for the asset in the dictionary specified by the\n`assets` field in the single-executable application configuration.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"An optional mime type for the blob.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Blob","links":[{"name":"Blob","href":"buffer.html#class-blob","start":0,"end":4}]},"description":""}},"description":"Similar to [`sea.getAsset()`](#seagetassetkey-encoding), but returns the result in a {Blob}.\nAn error is thrown when no matching asset can be found.","summary":"Similar to `sea.getAsset()`, but returns the result in a {Blob}. An error is thrown when no matching asset can be found.","examples":[],"children":[]},{"kind":"method","id":"seagetrawassetkey","name":"getRawAsset","title":"`sea.getRawAsset(key)`","scope":"module","overloadOf":null,"stability":null,"added":["v21.7.0","v20.12.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"key","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"the key for the asset in the dictionary specified by the\n`assets` field in the single-executable application configuration.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"ArrayBuffer","links":[{"name":"ArrayBuffer","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer","start":0,"end":11}]},"description":""}},"description":"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.\n\nUnlike `sea.getAsset()` or `sea.getAssetAsBlob()`, this method does not\nreturn a copy. Instead, it returns the raw asset bundled inside the executable.\n\nFor 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.","summary":"This method can be used to retrieve the assets configured to be bundled into the single-executable application at build time. An error is thrown when no matching asset can be found.","examples":[],"children":[]},{"kind":"method","id":"seagetassetkeys","name":"getAssetKeys","title":"`sea.getAssetKeys()`","scope":"module","overloadOf":null,"stability":null,"added":["v24.8.0","v22.20.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"An array containing all the keys of the assets\nembedded in the executable. If no assets are embedded, returns an empty array."}},"description":"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.","summary":"This method can be used to retrieve an array of all the keys of assets embedded into the single-executable application. An error is thrown when not running inside a single-executable application.","examples":[],"children":[]}]},{"kind":"section","id":"in-the-injected-main-script","name":"In the injected main script","title":"In the injected main script","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"module-format-of-the-injected-main-script","name":"Module format of the injected main script","title":"Module format of the injected main script","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"To specify how Node.js should interpret the injected main script, use the\n`mainFormat` field in the single-executable application configuration.\nThe accepted values are:\n\n* `\"commonjs\"`: The injected main script is treated as a CommonJS module.\n* `\"module\"`: The injected main script is treated as an ECMAScript module.\n\nIf the `mainFormat` field is not specified, it defaults to `\"commonjs\"`.\n\nCurrently, `\"mainFormat\": \"module\"` cannot be used together with `\"useSnapshot\"`.","summary":"To specify how Node.js should interpret the injected main script, use the `mainFormat` field in the single-executable application configuration. The accepted values are:","examples":[],"children":[]},{"kind":"section","id":"module-loading-in-the-injected-main-script","name":"Module loading in the injected main script","title":"Module loading in the injected main script","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"In the injected main script, module loading does not read from the file system.\nBy default, both `require()` and `import` 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.\n\nUsers can bundle their application into a standalone JavaScript file to inject\ninto the executable. This also ensures a more deterministic dependency graph.\n\nTo load modules from the file system in the injected main script, users can\ncreate a `require` function that can load from the file system using\n`module.createRequire()`. For example, in a CommonJS entry point:\n\n```js\nconst { createRequire } = require('node:module');\nrequire = createRequire(__filename);\n```","summary":"In the injected main script, module loading does not read from the file system. By default, both `require()` and `import` statements would only be able to load the built-in modules. Attempting to load a module that can only be found in the file system will throw an error.","examples":[{"language":"js","displayName":null,"code":"const { createRequire } = require('node:module');\nrequire = createRequire(__filename);"}],"children":[]},{"kind":"section","id":"require-in-the-injected-main-script","name":"require() in the injected main script","title":"`require()` in the injected main script","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"`require()` in the injected main script is not the same as the [`require()`](modules.html#requireid)\navailable to modules that are not injected.\nCurrently, it does not have any of the properties that non-injected\n[`require()`](modules.html#requireid) has except [`require.main`](modules.html#accessing-the-main-module).","summary":"`require()` in the injected main script is not the same as the `require()` available to modules that are not injected. Currently, it does not have any of the properties that non-injected `require()` has except `require.main`.","examples":[],"children":[]},{"kind":"section","id":"__filename-and-modulefilename-in-the-injected-main-script","name":"__filename and module.filename in the injected main script","title":"`__filename` and `module.filename` in the injected main script","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The values of `__filename` and `module.filename` in the injected main script\nare equal to [`process.execPath`](process.html#processexecpath).","summary":"The values of `__filename` and `module.filename` in the injected main script are equal to `process.execPath`.","examples":[],"children":[]},{"kind":"section","id":"__dirname-in-the-injected-main-script","name":"__dirname in the injected main script","title":"`__dirname` in the injected main script","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The value of `__dirname` in the injected main script is equal to the directory\nname of [`process.execPath`](process.html#processexecpath).","summary":"The value of `__dirname` in the injected main script is equal to the directory name of `process.execPath`.","examples":[],"children":[]},{"kind":"section","id":"importmeta-in-the-injected-main-script","name":"import.meta in the injected main script","title":"`import.meta` in the injected main script","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"When using `\"mainFormat\": \"module\"`, `import.meta` is available in the\ninjected main script with the following properties:\n\n* `import.meta.url`: A `file:` URL corresponding to [`process.execPath`](process.html#processexecpath).\n* `import.meta.filename`: Equal to [`process.execPath`](process.html#processexecpath).\n* `import.meta.dirname`: The directory name of [`process.execPath`](process.html#processexecpath).\n* `import.meta.main`: `true`.\n\n`import.meta.resolve` is currently not supported.","summary":"When using `\"mainFormat\": \"module\"`, `import.meta` is available in the injected main script with the following properties:","examples":[],"children":[]},{"kind":"section","id":"import-in-the-injected-main-script","name":"import() in the injected main script","title":"`import()` in the injected main script","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"When using `\"mainFormat\": \"module\"`, `import()` can be used to dynamically\nload built-in modules. Attempting to use `import()` to load modules from\nthe file system will throw an error.","summary":"When using `\"mainFormat\": \"module\"`, `import()` can be used to dynamically load built-in modules. Attempting to use `import()` to load modules from the file system will throw an error.","examples":[],"children":[]},{"kind":"section","id":"using-native-addons-in-the-injected-main-script","name":"Using native addons in the injected main script","title":"Using native addons in the injected main script","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Native addons can be bundled as assets into the single-executable application\nby specifying them in the `assets` 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 `process.dlopen()`.\n\n```json\n{\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```\n\n```js\n// 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```\n\nKnown caveat: if the single-executable application is produced by postject running on a Linux arm64 docker container,\n[the produced ELF binary does not have the correct hash table to load the addons](https://github.com/nodejs/postject/issues/105) and\nwill crash on `process.dlopen()`. Build the single-executable application on other platforms, or at least on\na non-container Linux arm64 environment to work around this issue.","summary":"Native addons can be bundled as assets into the single-executable application by specifying them in the `assets` field of the configuration file used to generate the single-executable application preparation blob. The addon can then be loaded in the injected main script by writing the asset to a temporary file and loading it with `process.dlopen()`.","examples":[{"language":"json","displayName":null,"code":"{\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}"},{"language":"js","displayName":null,"code":"// 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);"}],"children":[]}]},{"kind":"section","id":"notes","name":"Notes","title":"Notes","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"single-executable-application-creation-process","name":"Single executable application creation process","title":"Single executable application creation process","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The process documented here is subject to change.","summary":"The process documented here is subject to change.","examples":[],"children":[{"kind":"section","id":"1-generating-single-executable-preparation-blobs","name":"1. Generating single executable preparation blobs","title":"1. Generating single executable preparation blobs","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"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 `--build-sea`, this step is done internally along with the injection.","summary":"To build a single executable application, Node.js would first generate a blob that contains all the necessary information to run the bundled script. When using `--build-sea`, this step is done internally along with the injection.","examples":[],"children":[{"kind":"section","id":"dumping-the-preparation-blob-to-disk","name":"Dumping the preparation blob to disk","title":"Dumping the preparation blob to disk","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Before `--build-sea` 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.\n\nTo dump the preparation blob to disk for verification, use `--experimental-sea-config`.\nThis writes a file that can be injected into a Node.js binary using tools like [postject](https://github.com/nodejs/postject).\n\nThe configuration is similar to that of `--build-sea`, except that the\n`output` field specifies the path to write the generated blob file instead of\nthe final executable.\n\n```json\n{\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```","summary":"Before `--build-sea` was introduced, an older workflow was introduced to write the preparation blob to disk for injection by external tools. This can still be used for verification purposes.","examples":[{"language":"json","displayName":null,"code":"{\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}"}],"children":[]}]},{"kind":"section","id":"2-injecting-the-preparation-blob-into-the-node-binary","name":"2. Injecting the preparation blob into the node binary","title":"2. Injecting the preparation blob into the `node` binary","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"To complete the creation of a single executable application, the generated blob\nneeds to be injected into a copy of the `node` binary, as documented below.\n\nWhen using `--build-sea`, this step is done internally along with the blob generation.\n\n* If the `node` binary is a [PE](https://en.wikipedia.org/wiki/Portable_Executable) file, the blob should be injected as a resource\n  named `NODE_SEA_BLOB`.\n* If the `node` binary is a [Mach-O](https://en.wikipedia.org/wiki/Mach-O) file, the blob should be injected as a section\n  named `NODE_SEA_BLOB` in the `NODE_SEA` segment.\n* If the `node` binary is an [ELF](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format) file, the blob should be injected as a note\n  named `NODE_SEA_BLOB`.\n\nThen, the SEA building process searches the binary for the\n`NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2:0` [fuse](https://www.electronjs.org/docs/latest/tutorial/fuses) string and flip the\nlast character to `1` to indicate that a resource has been injected.","summary":"To complete the creation of a single executable application, the generated blob needs to be injected into a copy of the `node` binary, as documented below.","examples":[],"children":[{"kind":"section","id":"injecting-the-preparation-blob-manually","name":"Injecting the preparation blob manually","title":"Injecting the preparation blob manually","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Before `--build-sea` was introduced, an older workflow was introduced to allow\nexternal tools to inject the generated blob into a copy of the `node` binary.\n\nFor example, with [postject](https://github.com/nodejs/postject):\n\n1. Create a copy of the `node` executable and name it according to your needs:\n\n   * On systems other than Windows:\n\n   ```bash\n   cp $(command -v node) hello\n   ```\n\n   * On Windows:\n\n   ```text\n   node -e \"require('fs').copyFileSync(process.execPath, 'hello.exe')\"\n   ```\n\n   The `.exe` extension is necessary.\n\n2. Remove the signature of the binary (macOS and Windows only):\n\n   * On macOS:\n\n   ```bash\n   codesign --remove-signature hello\n   ```\n\n   * On Windows (optional):\n\n   [signtool](https://learn.microsoft.com/en-us/windows/win32/seccrypto/signtool) can be used from the installed [Windows SDK](https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/). If this step is\n   skipped, ignore any signature-related warning from postject.\n\n   ```powershell\n   signtool remove /s hello.exe\n   ```\n\n3. Inject the blob into the copied binary by running `postject` with\n   the following options:\n\n   * `hello` / `hello.exe` - The name of the copy of the `node` executable\n     created in step 4.\n   * `NODE_SEA_BLOB` - The name of the resource / note / section in the binary\n     where the contents of the blob will be stored.\n   * `sea-prep.blob` - The name of the blob created in step 1.\n   * `--sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2` - The\n     [fuse](https://www.electronjs.org/docs/latest/tutorial/fuses) used by the Node.js project to detect if a file has been injected.\n   * `--macho-segment-name NODE_SEA` (only needed on macOS) - The name of the\n     segment in the binary where the contents of the blob will be\n     stored.\n\n   To summarize, here is the required command for each platform:\n\n   * On Linux:\n     ```bash\n     npx postject hello NODE_SEA_BLOB sea-prep.blob \\\n         --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2\n     ```\n\n   * On Windows - PowerShell:\n     ```powershell\n     npx postject hello.exe NODE_SEA_BLOB sea-prep.blob `\n         --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2\n     ```\n\n   * On Windows - Command Prompt:\n     ```text\n     npx postject hello.exe NODE_SEA_BLOB sea-prep.blob ^\n         --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2\n     ```\n\n   * On macOS:\n     ```bash\n     npx postject hello NODE_SEA_BLOB sea-prep.blob \\\n         --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 \\\n         --macho-segment-name NODE_SEA\n     ```","summary":"Before `--build-sea` was introduced, an older workflow was introduced to allow external tools to inject the generated blob into a copy of the `node` binary.","examples":[{"language":"bash","displayName":null,"code":"cp $(command -v node) hello"},{"language":"text","displayName":null,"code":"node -e \"require('fs').copyFileSync(process.execPath, 'hello.exe')\""},{"language":"bash","displayName":null,"code":"codesign --remove-signature hello"},{"language":"powershell","displayName":null,"code":"signtool remove /s hello.exe"},{"language":"bash","displayName":null,"code":"npx postject hello NODE_SEA_BLOB sea-prep.blob \\\n    --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2"},{"language":"powershell","displayName":null,"code":"npx postject hello.exe NODE_SEA_BLOB sea-prep.blob `\n    --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2"},{"language":"text","displayName":null,"code":"npx postject hello.exe NODE_SEA_BLOB sea-prep.blob ^\n    --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2"},{"language":"bash","displayName":null,"code":"npx postject hello NODE_SEA_BLOB sea-prep.blob \\\n    --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 \\\n    --macho-segment-name NODE_SEA"}],"children":[]}]}]},{"kind":"section","id":"platform-support","name":"Platform support","title":"Platform support","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Single-executable support is tested regularly on CI only on the following\nplatforms:\n\n* Windows\n* macOS (arm64 only; x64 is not currently supported and is skipped in the\n  tests)\n* Linux (all distributions [supported by Node.js](https://github.com/nodejs/node/blob/main/BUILDING.md#platform-list) except Alpine and all\n  architectures [supported by Node.js](https://github.com/nodejs/node/blob/main/BUILDING.md#platform-list) except s390x)\n\nThis is due to a lack of better tools to generate single-executables that can be\nused to test this feature on other platforms.\n\nSuggestions for other resource injection tools/workflows are welcomed. Please\nstart a discussion at <https://github.com/nodejs/single-executable/discussions>\nto help us document them.","summary":"Single-executable support is tested regularly on CI only on the following platforms:","examples":[],"children":[]}]}]}