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
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
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.
--targets node8-linux
(or other versions) if your current node version is not supported by pkg
. –
Disadvantaged Solver the same thing using Bun. I added an entry to script in package.json, like this:
"scripts": {
"compile": "bun build src/main.ts --compile --outfile out"
I now run it like bun run compile
and i can use the out file like ./out
© 2022 - 2024 — McMap. All rights reserved.
https://www.npmjs.com/package/pkg
– Lingerie