Support for single executable applications is one of the key technical priorities identified for the success of Node.js.
From the Next-10 discussions there are 2 approaches the project believes are important to support:
This is the approach followed by boxednode.
No additional code within the Node.js project is needed to support the option of compiling a bundled application along with Node.js into a single executable application.
This is the approach followed by pkg.
The project does not plan to provide the complete solution but instead the key elements which are required in the Node.js executable in order to enable bundling with the pre-built Node.js binaries. This includes:
It is left up to external tools/solutions to:
However, the project also maintains a separate tool, postject, for injecting arbitrary read-only resources into the binary such as those needed for bundling the application into the runtime.
Planning for this feature takes place in the single-executable repository.
Currently, only running a single embedded CommonJS file is supported but support for the following features are in the list of work we'd like to get to:
To disable single executable application support, build Node.js with the --disable-single-executable-application configuration option.
When built with single executable application support, the Node.js process uses postject-api.h to check if the NODE_SEA_BLOB section exists in the binary. If it is found, it passes the buffer to single_executable_application.js, which executes the contents of the embedded script.