Node.js v26.9.0 documentation
- Node.js v26.9.0
- Table of contents
- Single executable applications
- Generating single executable applications with
--build-sea - Single-executable application API
- In the injected main script
- Module format of the injected main script
- Module loading in the injected main script
require()in the injected main script__filenameandmodule.filenamein the injected main script__dirnamein the injected main scriptimport.metain the injected main scriptimport()in the injected main script- Using native addons in the injected main script
- Notes
- Generating single executable applications with
- Single executable applications
- Index
- About this documentation
- Usage and example
- Assertion testing
- Asynchronous context tracking
- Async hooks
- Benchmark runner
- Buffer
- C++ addons
- C/C++ addons with Node-API
- C++ embedder API
- Child processes
- Cluster
- Command-line options
- Console
- Crypto
- Debugger
- Deprecated APIs
- Diagnostics Channel
- DNS
- Domain
- Environment Variables
- Errors
- Events
- File system
- FFI
- Globals
- HTTP
- HTTP/2
- HTTPS
- Inspector
- Internationalization
- Iterable Streams API
- Modules: CommonJS modules
- Modules: ECMAScript modules
- Modules:
node:moduleAPI - Modules: Packages
- Modules: TypeScript
- Net
- OS
- Path
- Performance hooks
- Permissions
- Process
- Punycode
- Query strings
- Readline
- REPL
- Report
- Single executable applications
- SQLite
- Stream
- String decoder
- Test runner
- Timers
- TLS/SSL
- Trace events
- TTY
- UDP/datagram
- URL
- Utilities
- V8
- Virtual File System
- VM
- WASI
- Web Crypto API
- Web Streams API
- Worker threads
- Zlib
- Other versions
- Options
Single executable applications#
Stability: 1.1 - Active development
This feature allows the distribution of a Node.js application conveniently to a system that does not have Node.js installed.
Node.js supports the creation of single executable applications by allowing
the injection of a blob prepared by Node.js, which can contain a bundled script,
into the node binary. During start up, the program checks if anything has been
injected. If the blob is found, it executes the script in the blob. Otherwise
Node.js operates as it normally does.
The single executable application feature supports running a single embedded script using the CommonJS or the ECMAScript Modules module system.
Users can create a single executable application from their bundled script
with the node binary itself and any tool which can inject resources into the
binary.
-
Create a JavaScript file:
echo 'console.log(`Hello, ${process.argv[2]}!`);' > hello.js -
Create a configuration file building a blob that can be injected into the single executable application (see Generating single executable preparation blobs for details):
- On systems other than Windows:
echo '{ "main": "hello.js", "output": "sea" }' > sea-config.json- On Windows:
echo '{ "main": "hello.js", "output": "sea.exe" }' > sea-config.jsonThe
.exeextension is necessary. -
Generate the target executable:
node --build-sea sea-config.json -
Sign the binary (macOS and Windows only):
- On macOS:
codesign --sign - sea- On Windows (optional):
A certificate needs to be present for this to work. However, the unsigned binary would still be runnable.
signtool sign /fd SHA256 sea.exe -
Run the binary:
- On systems other than Windows
$ ./sea world Hello, world!- On Windows
$ .\sea.exe world Hello, world!
Generating single executable applications with --build-sea#
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.
The configuration currently reads the following top-level fields:
{
"main": "/path/to/bundled/script.js",
"mainFormat": "commonjs", // Default: "commonjs", options: "commonjs", "module"
"executable": "/path/to/node/binary", // Optional, if not specified, uses the current Node.js binary
"output": "/path/to/write/the/generated/executable",
"disableExperimentalSEAWarning": true, // Default: false
"useSnapshot": false, // Default: false
"useCodeCache