Roll node.js applications into a single executable
Nexe is a command-line utility that compiles your Node.js application into a single executable file.
- Ability to run multiple applications with different node.js runtimes.
- Distributable binaries without needing node / npm.
- Starts faster.
- Lockdown specific application versions, and easily rollback.
- Faster deployments.
- Linux / Mac / BSD / Windows
- Windows: Python 2.6 or 2.7 (in PATH), Visual Studio 2010 or 2012
- Use the techniques below for working around dynamic require statements to exclude the module from the bundling, and deploy along side the executable in a node_module folder so your app can find it. Note: On windows you may need to have your app be named node.exe if .node file depends on node.
var x = requiresomeVar;
In this case nexe won't bundle the file
var x;if someCheckx = require"./ver1.js";elsex = require"./var2.js";
In this case nexe will bundle both files.
- for dynamic requires that you want bundled add the following into your project
var dummyToForceIncludeForBundle = false;if dummyToForceIncludeForBundlerequire"./loadedDynamicallyLater.js";// ...
this will trick the bundler into including them.
- for dynamic files getting included that you don't want to be
var moduleName = "./ver2.js";if someCheckmoduleName = "./ver1.js";var x = requiremoduleName;
Note: neither file will be bundled.
Using these two techniques you can change your application code so modules are not bundles, and generate a includes.js file as part of your build process so that the right files get bundled for your build configuration.
Once the module is bundled it is part of the executable. __dirname is therefore the executable dir (process.execPath). Thus if you put resources on a relative path from the the executable your app will be able to access them.
If you had a data file at
and a file at
moduleexports = fwreadFileSyncpathjoin__dirname "./data/some.csv";
You would need to deploy some.csv in a sub dir
data/ along side your executable
There are potential use cases for __dirname where the executable path is not the correct substitution, and could result in a silent error (possibly even in a dependency that you are unaware of).
Note: __filename will be 'undefined'
child_process.spawn works is unmodified, but child_process.fork will make an attempt to lunch a new instance of your executable and run the bundled module.
npm install nexe [-g]
var nexe = require'nexe';nexecompileinput: 'input.js'output: 'path/to/bin'nodeVersion: '0.12.0'nodeTempDir: __dirnamepython: 'path/to/python'resourceFiles: 'path/to/a/file'flags: trueconsole.logerr;;