create single executables out of your [node/io].js applications
Nexe is a command-line utility that compiles your Node.js application into a single executable file.
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.
var dummyToForceIncludeForBundle = false;if dummyToForceIncludeForBundlerequire"./loadedDynamicallyLater.js";// ...
this will trick the bundler into including them.
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 launch a new instance of your executable and run the bundled module.
npm install nexe [-g]
var nexe = require'nexe';nexecompileinput: 'input.js' // where the input file isoutput: 'path/to/bin' // where to output the compiled binarynodeVersion: '5.5.0' // node versionnodeTempDir: 'src' // where to store node source.nodeConfigureArgs: 'opt' 'val' // for all your configure arg needs.nodeMakeArgs: "-j" "4" // when you want to control the make process.python: 'path/to/python' // for non-standard python setups. Or python 3.x forced ones.resourceFiles: 'path/to/a/file' // array of files to embed.resourceRoot: 'path/' // where to embed the resourceFiles.flags: true // use this for applications that need command line flags.jsFlags: "--use_strict" // v8 flagsframework: "node" // node, nodejs, or iojsiferrreturn console.logerr;// do whatever;
As of 0.4.0 you can now embed nexe options into package.json. Note that this Format is still in works, so it is likely to change.
If you have requires that aren't resolving well, you can do two things.
Try adding it to
nexe.browserify.requires in your
Or, if that doesn't work (it tends to not work sometimes), you can try altering browserify.paths like so:
If it still doesn't work, file a bug with what you tried! (also try using