How to make exe files from a node.js app?
There a few alternatives, both free and commercial. I haven't used any of them but in theory they should work:
- Iexpress (native windows tool)
- Quick Batch File Compiler (commercial)
- BoxedApp Packer
- "Advanced" Batch To EXE Converter" (freeware)
Most will require you to keep the batch file as main executable, and then bundle node.exe and your scripts.
Depending on your script, you also have the option to port it to JSDB, which supports an easy way to create executables by simply appending resources to it.
A third quasi-solution is to keep node somewhere like C:\utils
and add this folder to your PATH
environment variable. Then you can create .bat files in that dir that run node + your preferred scripts - I got coffeescript's coffee
working on windows this way. This setup can be automated with a batch file, vb script or installer.
The solution I've used is Roger Wang's node-webkit.
This is a fantastic way to package nodejs apps and distribute them, it even gives you the option to "bundle" the whole app as a single executable. It supports windows, mac and linux.
Here are some docs on the various options for deploying node-webkit apps, but in a nutshell, you do the following:
- Zip up all your files, with a package.json in the root
- Change the extension from .zip to .nw
- copy /b nw.exe+app.nw app.exe
Just as an added note - I've shipped several production box/install cd applications using this, and it's worked great. Same app runs on windows, mac, linux and over the web.
Update: the project name has changed to 'nw.js' and is properly located here: nw.js
For anyone stumbling upon this question, there are now two projects that create exes out of your node projects, Pkg and Electron.atom.io, they differ slightly:
- Pkg will compile your project to native code, they also include assets AND a NodeJS installation (the system won't need to install NodeJS to run the executable). Your source code will not be included.
The resulting executable is Windows ONLY ( .exe ).All platforms are supported now.It now requires a licence for commercial products.Fully open source. - Electron.atom.io while it will not compact and generate an executable for you, it CAN be used to distribute NodeJS apps since they offer a way to distribute applications. The benefits are that electron is multi-platform (Windows, macOS, Linux), the cons are that your source code WILL be included, even though they offer a way to distribute your app inside an asar archive. It will not be bulletproof but it's still better than your source in plain.
The best tool I know is NodeJS tool: zeit/pkg
It is very easy to use (much more than Nexe, just as an example), you can just install in globally:
npm install -g pkg
to create executables for macOS, Linux and Windows:
pkg exampleApp.js
I had a bit of complicated code which used NodeJS socket server, I tried different applications, none of them created it properly, except zeit/pkg.