This is a template for creating Single Executable Applications (SEA) for Node.js Express.js servers, using TypeScript and esbuild. The build process is containerized with Docker to allow for cross-platform builds.
- Node.js SEA: Package your application into a single executable.
- Express.js: A minimal and flexible Node.js web application framework.
- TypeScript: A typed superset of JavaScript that compiles to plain JavaScript.
- esbuild: An extremely fast JavaScript bundler and minifier.
- Docker: Containerize the build process for cross-platform compatibility.
-
Install dependencies:
npm install
npm start: Start the application from the bundled output.npm run dev: Start the application in development mode with file watching.npm run clean: Remove thedistdirectory.npm run build:ts: Build the TypeScript source code using esbuild.npm run build:sea: Build the Single Executable Application for the host machine.npm run build:docker:arm64: Build a Docker image forlinux/arm64.npm run build:docker:amd64: Build a Docker image forlinux/amd64.npm run extract:sea:arm64: Extract thelinux/arm64executable from its Docker image.npm run extract:sea:amd64: Extract thelinux/amd64executable from its Docker image.
To build the SEA on your local machine, run the following command:
npm run build:seaThis will generate an executable file named app in the dist directory.
To build the SEA for a different architecture (e.g., linux/arm64 or linux/amd64), you can use the provided Docker scripts.
-
Build the Docker image for your target platform:
For
linux/arm64:npm run build:docker:arm64
For
linux/amd64:npm run build:docker:amd64
-
Extract the executable from the Docker image:
After building the image, run the corresponding extraction script.
For
linux/arm64:npm run extract:sea:arm64
For
linux/amd64:npm run extract:sea:amd64
This will copy the executable from the Docker container to your local
distdirectory, namedapp-linux-arm64orapp-linux-amd64.
.
├── dist/ # Compiled output
├── scripts/ # Build scripts
│ ├── build-sea.js # Script for building the SEA
│ └── extract-sea.sh # Script for extracting the SEA from Docker
├── src/ # Source code
│ └── index.ts # Main application file
├── .dockerignore # Files to ignore in Docker builds
├── Dockerfile # Docker configuration
├── package.json # Project dependencies and scripts
├── sea-config.json # SEA configuration
├── tsconfig.json # TypeScript configuration
└── README.md # This file
This project is licensed under the MIT License.