crashmax-dev / node-sea

Node.js single executable application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Single executable applications

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.

Note

The single executable application feature currently only supports running a single embedded script using the CommonJS 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.

  1. Create a JavaScript file:
// index.js
console.log(`Hello, ${process.argv[2]}!`)
  1. Create a configuration file building a blob that can be injected into the single executable application:
// sea-config.json
{
  "main": "index.js",
  "output": "sea-prep.blob"
}
  1. Generate the blob to be injected:
node --experimental-sea-config sea-config.json
  1. Create a copy of the node executable and name it according to your needs:
cp $(command -v node) bin
  1. Inject the blob into the copied binary by running postject with the following options:
npx postject bin NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2
  1. Run the binary:
./bin world
Hello, world!

About

Node.js single executable application


Languages

Language:JavaScript 100.0%