Single executable applications#

Stability: 1.1 - Active development

Source Code: src/node_sea.cc

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

Here are the steps for creating a single executable application using one such tool, postject:

  1. Create a JavaScript file:

    echo 'console.log(`Hello, ${process.argv[2]}!`);' > hello.js 
  2. Create a configuration file building a blob that can be injected into the single executable application (see Generating single executable preparation blobs for details):

    echo '{ "main": "hello.js", "output": "sea-prep.blob" }' > sea-config.json 
  3. Generate the blob to be injected:

    node --experimental-sea-config sea-config.json 
  4. Create a copy of the node executable and name it according to your needs:

    • On systems other than Windows:
    cp $(command -v node) hello 
    • On Windows: