This project demonstrates how to create a Single Executable Application (SEA) using Node.js. SEAs allow you to bundle your Node.js application into a single binary executable, making it easier to distribute and run without requiring Node.js installation on the target machine. For more information about SEAs, see the official Node.js documentation.
- Node.js (v16 or later)
- macOS (for this specific example; SEA supports other platforms with slight modifications)
- npm (Node Package Manager)
.
├── hello.ts # Main application entry point
├── lib/ # Application modules
│ └── greeter.ts # Example module
├── dist/ # Build output directory
│ ├── bundled/ # Contains bundled application
│ ├── sea/ # Contains SEA preparation files
│ └── transpiled/ # Contains compiled TypeScript
├── build-bundle.js # esbuild bundling script
├── build-sea.js # SEA creation script
├── sea-config.json # SEA configuration
└── tsconfig.json # TypeScript configuration
-
Clone this repository:
git clone <repository-url> cd node-sea
-
Install dependencies:
npm install
-
The project uses TypeScript for type safety. The main application code is in
hello.ts
. -
To run the application in development mode:
npm start
The build process consists of several steps, all automated through npm scripts:
-
Clean the previous build:
npm run clean
-
Build everything in one go:
npm run build:all
Or, you can run each step individually:
-
Compile TypeScript:
npm run build:js
This compiles TypeScript files to JavaScript in the
dist/transpiled
directory. -
Bundle the application:
npm run build:bundle
This uses esbuild to bundle all dependencies into a single file at
dist/bundled/bundle.js
. -
Create the SEA binary:
npm run build:sea
This script:
- Generates the SEA preparation blob
- Copies the Node.js binary
- Injects the application code
- Signs the binary (macOS specific)
After building, you'll find an executable named hello
in the dist directory. You can run it with or without parameters:
./dist/hello FAF
Hello, FAF!
This binary contains everything needed to run your application, including the Node.js runtime.
The project uses TypeScript for type safety. The tsconfig.json
configures the compilation process, outputting to dist/transpiled
.
The build-bundle.js
script uses esbuild to:
- Bundle all dependencies
- Minify the code
- Generate source maps
- Output a single file in CommonJS format
The build-sea.js
script handles the SEA creation process:
- Generates a preparation blob using
sea-config.json
- Copies the Node.js binary
- Removes existing signatures (macOS specific)
- Injects the application code into the binary
- Signs the resulting binary (macOS specific)
- Modify
hello.ts
and files inlib/
for your application logic - Update
sea-config.json
if you change the entry point - Adjust
build-bundle.js
for different bundling options - Modify
build-sea.js
for platform-specific requirements
- The SEA binary is platform-specific; you'll need to build it on each target platform
- Source maps are included for debugging, but not used in the final SEA
- The build process is optimized for macOS but can be adapted for other platforms
ISC
Here are some potential enhancements that could be implemented to improve the project:
-
Automated Testing
- Add unit tests for core functionality using Jest or Mocha
- Implement integration tests for the SEA build process
- Add end-to-end testing for the executable
- Set up test coverage reporting
-
Continuous Integration/Deployment
- Set up GitLab CI/CD pipeline
- Implement automated builds for different platforms
- Add automated release management
- Configure deployment workflows
-
Code Quality
- Integrate Biome for code formatting and linting
- Implement SonarQube for code quality metrics
- Set up pre-commit hooks for code quality checks
-
Documentation
- Add JSDoc documentation for all functions
- Generate API documentation
- Create contribution guidelines
- Add architecture diagrams
-
Performance
- Implement build size optimization
- Add performance benchmarking
- Optimize startup time
- Implement caching strategies
Contributions are welcome! Please feel free to submit a Pull Request.
- Node.js Single Executable Applications Documentation - Official documentation for creating and working with SEAs