Is it possible to compile a JS application and the NodeJS interpreter into a single executable for distribution?
views:
138answers:
4Mozilla has a Javascript->Java compiler, which would presumably turn both node.js and your application code into Java bytecode that could run as a single executable. Much of node.js' speed supposedly comes from the V8 Javascript interpreter, though, so you'll have to benchmark to see which approach performs better.
Another option would to be use Google's JS Compiler. This is not true compilation -- the output is still Javascript -- but it will minify and heavily optimize your code. Both node.js and your application code could in theory be "compiled" together using this approach and run on V8.
I havent seen anything like this done just yet, maybe because node.js is still very young. You could perhaps use a "file concatenator" and put everything in just one file, this might work:
find . -name '*.js' -type f -exec cat '{}' >> final.js \;
you can perhaps run an optimizer (like this for example) to have a smaller file.
Hope it helps.
Is it possible to compile a JS application and the NodeJS interpreter into a single executable for distribution?
This might sound obvious, but here's my take on it.
A "single executable for distribution" sounds a lot like an installer...
An installer would contain or be able to fetch online your js scripts and a compiled node.js. It would unpack everything and create a script in /etc/init.d/ to start and stop the server.
If all your clients are on the same distro (e.g. Debian), I'd just make a package for the appropriate packaging tool (e.g. apt) and let the package tool handle everything.
It the clients all have different distros, you could look into autopackage.
you need a linux box with git and python, then ugly solution:
$ git clone git://github.com/ry/node.git
$ cd node
$ vim src/node.js # add your code to end before "process.loop();"
$ ./configure
$ make
$ sudo make install
$ node