https://github.com/crashmax-dev/node-sea
Node.js single executable application
https://github.com/crashmax-dev/node-sea
Last synced: about 1 year ago
JSON representation
Node.js single executable application
- Host: GitHub
- URL: https://github.com/crashmax-dev/node-sea
- Owner: crashmax-dev
- Created: 2023-04-20T12:49:52.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-03-10T07:02:48.000Z (about 2 years ago)
- Last Synced: 2025-03-28T22:34:59.653Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 10.7 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Single executable applications
> Node.js supports the creation of [single executable applications](https://github.com/nodejs/single-executable) 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.
> [!NOTE]
> The single executable application feature currently only supports running a single embedded script using the [CommonJS](https://nodejs.org/api/modules.html#modules-commonjs-modules) module system.
> [!WARNING]
> This guide to work in Linux, if you need to build an application for another platform (Windows, macOS), you should [read this](https://nodejs.org/api/single-executable-applications.html).
1. Create a JavaScript file:
```js
// index.js
console.log(`Hello, ${process.argv[2]}!`)
```
2. Create a configuration file building a blob that can be injected into the single executable application:
```json
// sea-config.json
{
"main": "index.js",
"output": "sea-prep.blob"
}
```
3. Generate the blob to be injected:
```bash
node --experimental-sea-config sea-config.json
```
4. Create a copy of the node executable and name it according to your needs:
```bash
cp $(command -v node) bin
```
5. Inject the blob into the copied binary by running postject with the following options:
```bash
npx postject bin NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2
```
6. Run the binary:
```bash
./bin world
Hello, world!
```