views:

138

answers:

4

Is it possible to compile a JS application and the NodeJS interpreter into a single executable for distribution?

A: 

Mozilla 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.

Eric Nguyen
NodeJS is a JS interpreter, much like Rhino, but written in C around the V8 engine... I don't think that would go through a javascript->java compiler without causing some issues!
digitala
Ah, you're right. Scratch that!
Eric Nguyen
A: 

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.

Purefan
A: 

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.

no
+1  A: 

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
Lauri
Ugly indeed. I think you'd better overwrite the `if (process.argv[1]) {...module.runMain()` part in `src/node.js`, and load your code as a root module instead of inserting it verbatim. I haven't tested though.
Pumbaa80
the idea was guide digitala to read the nodejs source code :)
Lauri
Good one. +1 for that :D
Pumbaa80