Question

Is there any software that I can use to compile nodejs program?

The reason I want to compile nodejs code is to make it safely distributable. For example for a desktop application,etc.

And also I want to know whether nodejs will execute faster if compiled as it is asynchronous already?

Was it helpful?

Solution

Javascript is not a compiled language and Node.js is Javascript. It will be executed and interpreted at runtime. You can process your javascript with tool like grunt.js for example lint-test and uglify it, but be careful so that do not break the npm system since it is based on certain conventions.

To package your javascript for distribution in the node.js context build an npm module. https://www.npmjs.org/doc/developers.html

For distributing javascript to the desktop client: Remember it's Javascript an it need to be executed in the Javascript VM. So to have some UI you need to run it in the browser or you need to have some webkit compiled dll to run your code... something like this... http://www.tidesdk.org/

You can also use: http://github.com/rogerwang/node-webkit (Thanks to @edi9999)

OTHER TIPS

There is no way to do that with v8, it has only JIT option. It possible to make a "snapshot" with v8, but it's not exactly the same as compilation and node.js doesn't have support for this feature (also it might produce slower code). Also all your code will be available with toString() of functions.

You might be interested in JXcore project. It is a fork of node and as far as I know has some solution to code protection. Also one of the project goals is to develop javascript-to-LLVM compiler. Of course it can't have full support for ES specification (eval, new Function etc).

There's no way to 'compile' a nodejs program, as the javascript is interpreted at run time.

However, if you want to protect your code, you could maybe use something like Uglify JS to make the javascript less readable. However, this won't hinder people to change around your code.

The closest you might get to acheiving your goal is to create a self-executing Javascript bytecode wrapper.

A project that does this is pkg

It somehow creates a self-contained binary executable from Javascript, including module dependencies and asset files and produces a self-contained executable.

Installation and use is easy:

$ npm install -g pkg
$ pkg index.js -o my-program
$ ./my-program

It seems the resulting binary contains nodejs bytecode. It appears that you can cross-compile.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top