0

So, I'm trying to pack a simple hello world script into an executeable, yet when using pkg or nexe, it looks like the entirety of Node.js get's packed in there, as they are way bigger than they need to be (around 30 MB). I did stumble upon EncloseJS, however, it was last updated in 2017 and no longer works (and the owner themself advices you to switch to pkg).

So, are there any other things out there that can compile it better than that?

Thanks in advance!

Also: This is the stunningly complex script that needs to run

console.log("StackOverflow is amazing!");
setTimeout(() => {
   process.exit(0);
}, 2000);

And my locally installed versions:

NPM Node
6.14.12 14.16.1
JoLoZ
  • 47
  • 6
  • Does this answer your question? [How to make exe files from a node.js app?](https://stackoverflow.com/questions/8173232/how-to-make-exe-files-from-a-node-js-app) – Ethicist May 22 '21 at 20:04
  • There's also at least 8 linked threads that could be duplicates in a comment to the topic. – Ethicist May 22 '21 at 20:05
  • Nodejs is a monolith that contains libuv, the V8 Javascript runtime and the nodejs libraries. It isn't modular so that you can link in only the parts of it that you actually use. If you want a small executable, don't use nodejs for your environment. Even with a true compiled and dynamically linked language such as C, you're going to still have the whole runtime library DLL as part of your distribution, even though the EXE itself can be very small. – jfriend00 May 22 '21 at 22:02

1 Answers1

1

No, pkg and nexe works like that - they melting your code and NodeJS in one executable. Because, basically, you need NodeJS to run nodejs scripts - there is some specific methods like fs, for example, witch not exist in regular js.

Anyway, on this moment there is some projects to view:

  1. NectarJS - project with actual dev status, basically compiles JS to C. But their main objectives is pretty interesting.

  2. There is small JS engine called QuickJS witch compiles JS to C.

  3. Another option is ts2c witch translate JS to C, but it does not support much features.

But keep in mind, that non of them works as good as pkg, witch fully support latest JS features and all NodeJS methods.

tarkh
  • 2,424
  • 1
  • 9
  • 12
  • A compiler is what I'm looking for. I kinda already figured that I can't run pure scripts without Node.js – JoLoZ May 22 '21 at 20:02