npm version License: MIT Node.js Version Downloads GitHub Stars GitHub Issues
A powerful cross-platform npm module for building Node.js applications into single executable files using Node.js Single Executable Applications (SEA) feature.
Installation β’ Quick Start β’ Documentation β’ Examples β’ Contributing
- π Build single executable applications from Node.js projects
- π True cross-platform support - Build for Linux, macOS, and Windows from any platform
- π₯ Automatic Node.js downloading - Downloads compatible Node.js binaries from the internet
- π¦ Simple CLI interface
- βοΈ Configurable build options
- π― Support for assets bundling
- π§ Code cache and snapshot optimization
- π Version management - Uses Node.js versions 19.9.0+ with smart version selection
- Node.js >= 18.16.0 (for SEA support)
- npm or yarn
npm install -g node-package-builder
npm install node-package-builder
node-package-builder init my-app
cd my-appnode-package-builder build
./app
node-package-builder build [options]
-m, --main <file>: Main JavaScript file (default: "index.js")-o, --output <name>: Output executable name (default: "app")-p, --platforms <platforms>: Target platforms, comma-separated (default: "linux,darwin,win32")--use-snapshot: Enable snapshot support (default: false)--use-code-cache: Enable code cache (default: false)--assets <assets>: Assets to include as JSON string (default: "{}")--disable-warning: Disable experimental SEA warning (default: true)
# Build for current platform node-package-builder build # Build for multiple platforms node-package-builder build --platforms linux,darwin,win32 # Build with custom main file and output name node-package-builder build --main src/app.js --output myapp # Build with assets node-package-builder build --assets '{"config.json": "./config.json", "data.txt": "./data.txt"}' # Build with optimizations node-package-builder build --use-code-cache --use-snapshot
# List supported platforms node-package-builder platforms # Initialize a sample project node-package-builder init [project-name] # Clean up temporary build files node-package-builder cleanup # Show help node-package-builder --help
const NodePackageBuilder = require('node-package-builder'); async function buildApp() { const builder = new NodePackageBuilder({ main: 'src/index.js', output: 'myapp', platforms: ['linux', 'darwin', 'win32'], useCodeCache: true, assets: { 'config.json': './config.json' } }); try { const results = await builder.build(); console.log('Build results:', results); } catch (error) { console.error('Build failed:', error); } } buildApp();
| Option | Type | Default | Description |
|---|---|---|---|
main |
string | 'index.js' |
Entry point of your application |
output |
string | 'app' |
Name of the output executable |
platforms |
array | ['linux', 'darwin', 'win32'] |
Target platforms to build for |
useSnapshot |
boolean | false |
Enable V8 snapshot for faster startup |
useCodeCache |
boolean | false |
Enable code cache for faster startup |
assets |
object | {} |
Additional files to bundle |
disableExperimentalSEAWarning |
boolean | true |
Disable experimental feature warning |
tempDir |
string | os.tmpdir()/node-package-builder |
Custom temporary directory for build files |
NEW: True Cross-Platform Support! π
You can now build executables for any platform from any platform:
# Build for all platforms from macOS node-package-builder build --platforms linux,darwin,win32 # Build Windows executable from Linux node-package-builder build --platforms win32 # Build Linux executable from Windows node-package-builder build --platforms linux
- Automatic Node.js Download: Downloads compatible Node.js binaries (v19.9.0+) from nodejs.org
- Smart Version Selection: Prefers stable LTS versions (20.x series) for maximum compatibility
- Local Caching: Downloaded binaries are cached in
~/.node-package-builder/cache/ - Platform-Specific Optimization: Automatically adjusts build settings per platform
- Same platform: Uses your local Node.js executable
- Different platform: Downloads and uses platform-specific Node.js binary
useSnapshotanduseCodeCacheare automatically disabled for cross-platform builds- Windows builds include automatic
.exeextension
- Minimum version: 19.9.0 (required for SEA support)
- Preferred versions: 20.18.0, 20.17.0, 20.16.0, 20.15.1
- Fallback version: 20.18.0 if internet is unavailable
- Maximum version: 22.x (for stability)
NEW: Smart Temporary File Handling! π§Ή
The builder now uses a sophisticated temporary file system to prevent conflicts and ensure clean builds:
- Isolated Build Directories: Each build gets a unique temporary directory
- Automatic Cleanup: Temporary files are automatically cleaned after each build
- Conflict Prevention: Multiple simultaneous builds won't interfere with each other
- Manual Cleanup: Clean up all temporary files with the cleanup command
- Unique Build IDs: Each build gets a unique ID (timestamp + random hash)
- Temporary Directory: Files are created in
os.tmpdir()/node-package-builder/build-{id}/ - Automatic Cleanup: Temporary directory is removed after build completion
- Manual Cleanup: Use
node-package-builder cleanupto remove all temporary directories
# Build with automatic cleanup node-package-builder build # Manual cleanup of all temporary files node-package-builder cleanup # Custom temporary directory const builder = new NodePackageBuilder({ main: 'index.js', tempDir: '/custom/temp/path' });
const { cleanupAllTempDirs } = require('node-package-builder'); // Clean up all temporary directories cleanupAllTempDirs();
You can bundle additional files with your executable:
const builder = new NodePackageBuilder({ main: 'index.js', assets: { 'config.json': './config/production.json', 'templates/main.html': './src/templates/main.html', 'data.txt': './data/sample.txt' } });
Access bundled assets in your application:
const fs = require('fs'); const { getAsset } = require('node:sea'); // Read bundled asset const config = JSON.parse(getAsset('config.json', 'utf8')); const template = getAsset('templates/main.html', 'utf8');
- Code signing is automatically handled
- Requires Xcode command line tools for signing
.exeextension is automatically added- Optional code signing with signtool
- No additional requirements
- Executable permissions are set automatically
-
"postject not found"
npm install -g postject
-
Permission denied on macOS/Linux
chmod +x ./your-app
-
Code signing issues on macOS
- Install Xcode command line tools:
xcode-select --install - Or disable signing warnings in system preferences
- Install Xcode command line tools:
-
Large executable size
- Use
--use-code-cachefor better compression - Minimize dependencies in your application
- Use
-
Build conflicts with multiple builds
# Clean up temporary files node-package-builder cleanup -
Temporary files not cleaned up
- Temporary files are automatically cleaned after each build
- Use
node-package-builder cleanupto manually clean all temp files - Check
os.tmpdir()/node-package-builder/for any remaining files
Check out the examples/ directory for sample projects:
- Simple CLI application
- Web server application
- Application with bundled assets
For detailed API documentation with TypeScript support, see the generated JSDoc documentation:
npm run docs
The documentation will be generated in the docs/ directory.
This package includes full TypeScript definitions. You can use it in TypeScript projects:
import NodePackageBuilder from 'node-package-builder'; const builder = new NodePackageBuilder({ main: 'src/index.ts', output: 'myapp', platforms: ['linux', 'darwin', 'win32'] });
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository:
https://github.com/sw3do/node-package-builder - Clone your fork:
git clone https://github.com/sw3do/node-package-builder.git - Install dependencies:
npm install - Create your feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Run type checking:
npm run type-check - Generate documentation:
npm run docs - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow the existing code style
- Add JSDoc comments for all public methods
- Include TypeScript definitions
- Write tests for new features
See CHANGELOG.md for a detailed history of changes.
- π Documentation
- π Issue Tracker
- π¬ Discussions
- π§ Contact
MIT License - see LICENSE file for details.
sw3do - GitHub
- Node.js Single Executable Applications - Official Node.js SEA documentation
- postject - Tool for injecting arbitrary read-only resources into executable files
- pkg - Alternative packaging solution for Node.js
- nexe - Another Node.js executable builder
Made with β€οΈ by sw3do
β Star this project if you find it useful!