Node.js v18.20.0 documentation


Table of contents

Single executable applications#

Stability: 1 - Experimental: This feature is being designed and will change.

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 JavaScript file into the node binary. During start up, the program checks if anything has been injected. If the script is found, it executes its contents. Otherwise Node.js operates as it normally does.

The single executable application feature only supports running a single embedded CommonJS file.

A bundled JavaScript file can be turned into a single executable application with any tool which can inject resources into the node 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 copy of the node executable and name it according to your needs:

    $ cp $(command -v node) hello 
  3. Remove the signature of the binary:

    • On macOS:
    $ codesign --remove-signature hello 
    • On Windows (optional):

    signtool can be used from the installed Windows SDK. If this step is skipped, ignore any signature-related warning from postject.

    $ signtool remove /s hello 
  4. Inject the JavaScript file into the copied binary by running postject with the following options: