13,568
stars
+0+-2+3
554
forks
155
watchers
183
prs
922
issues
4
releases
–
discussions
README
Install: npm i nexe -g
Nexe is a command-line utility that compiles your Node.js application into a single executable file.
Motivation and Features
- Self contained applications
- Ability to run multiple applications with different node.js runtimes.
- Distribute binaries without needing node / npm.
- Idempotent builds
- Start and deploy faster.
- Lockdown specific application versions, and easily rollback.
- Flexible build pipeline
- Cross platform builds
Usage
- Application entrypoint:
nexe my-app.js
- stdin interface
rollup -c | nexe --resource "./public//" -o my-app.exe
For more CLI options see: nexe --help
Examples
- nexe server.js -r "public//.html"
- nexe --build
- nexe -t x86-8.0.0
Resources
Additional files or resources can be added to the binary by passing -r "glob/pattern//". These included files can be read in the application by using fs.readFile or fs.readFileSync.
Compiling the nexe Executable
By default nexe will attempt to download a pre-built executable. These are listed on the releases page. The exact version you want may be unavailable or you may want to customize what is built. See nexe --help for a list of options available when passing the --build option. You will also need to ensure your environment is setup to build node. Note: the python binary in your path should be an acceptable version of python 3; you can create a symlink or use the --python parameter (e.g. nexe --build --python=$(which python3)).
Linux and macOS
Prerequisites & details
Windows
The fastest and most reliable way to get started is simply to run the commands below. If you'd rather read the details or perform a manual install of the prerequisites, you can find that here.
The instructions below are the fastest and most reliable method.
Run the following sets of commands with PowerShell (running as Administrator).
Install all required build tools (and dependencies):
Set-ExecutionPolicy Unrestricted -Force
iex ((New-Object System.Net.WebClient).DownloadString('https://boxstarter.org/bootstrapper.ps1'))
get-boxstarter -Force
Install-BoxstarterPackage https://raw.githubusercontent.com/nodejs/node/master/tools/bootstrap/windows_boxstarter -DisableReboots
Set config:
npm config set msvs_version 2019
npm config set python python3.8
Where 2019 is the version of Visual Studio you have (if you have it).
Notes:
- The above works and has been tested with node.js 14.5.4 and 15.8.0
- Python 3 and Python 2 can coexist and nexe will still work, considering the set config area above
- Don't use npm install windows-build-tools unless you're having some type of issue, because the above commands configures and installs the latest/preferred too.
Node.js API
Example
javascript
const { compile } = require('nexe')
compile({
input: './my-app.js',
build: true, //required to use patches
patches: [
async (compiler, next) = {
await compiler.setFileContentsAsync(
'lib/new-native-module.js',
'module.expor