compile NodeJS to binary

Viewed 7229

i want to compile nodeJS into binary, similar to C/C++.
compile

$NodeCompile -ofast Node.js -o executable

(fine if i can't do compiler settings)

to run it

$./executable
1 Answers

You probably want to look at pkg

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

Installation and use is easy:

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

My understanding is that this binary contains nodejs bytecode. It also appears that you can cross-compile.

Note: I've tried ncc and nexe also, but I haven't found them to be as useful. ncc just creates a self-contained Javascript file and nexe encountered a Python error when I tried to use it.

Related