This question already has an answer here:
- How to make exe files from a node.js app? 17 answers
I'm trying to find a way to use a command line nodejs application that I created on a computer without node.js installed. In other words how to package my application with node.js inside, in order to avoid the users to have node.js already installed.
The tipical use case is: I run the application and the application works using the node core that is provide with the application (or the application checks if there is node.js installed, and if not it download and install it automatically).
Do you have any idea?
There are few but Node-webkit looks like the clear winner at the moment. A previous alternative appjs was deprecated, here is the related tweet:
Have a look at the apps already written.
Checking the Node.js License, it appears that it is MIT licensed, so it's perfectly legal to do so.
I'm assuming you're targeting Windows or Mac, since on Linux you could just release a package that depends on Node.js of a particular version, and provide a script to add one of the various free repositories for
.deb
or.rpm
pre-compiled versions of Node.js.You'll need to get the source for the version you're interested in and build it for your platform of choice. As I recall, the built executable can be run directly without being installed, but it assumes certain libraries are available on the
$PATH
(OpenSSL being the one they're explicitly mentioning in the license as liked instead of statically compiled into the binary).Reading the Visual Studio build script, it looks like you'll need Python to be installed for Windows to build the
.exe
. I suspect (but don't know for sure) that the executable is essentially stand-alone for Windows, so you can bundle your Javascript code with it and write a simple batch file to get it running on that platform. I have no idea how to make a Windows.msi
installer, but the vcbuild.bat file also includes the ability to generate one, so you could just piggyback on their code to do it.JXcore allows you to do that.
Once you have JXcore installed on windows (or unix systems), all you have to do is run:
This will produce a .exe (or unix executable if the command was run on a unix system) file that you can distributed and can be executed without any external dependencies whatsoever (you don't even need JXcore nor Node.js on the system).
Here's the documentation on that functionality: http://jxcore.com/packaging-code-protection/#cat-74
(Duplicate of https://stackoverflow.com/a/27551233/810830)
Python, Perl and Tcl all have utilities that will take a script and create an executible for a given platform. (I don't know about Ruby, PHP etc.) -- so far, no utility like this exists for nodejs, but I would be interested in one existing as well.
There is a build option in node to have it run a specified script on launch, so some of the plumbing is there.