From future self: Question was made by silly me who didn't know compilation process and how Node.js work with native bindings, future me have done native bindings and ffi and improved question to be more "googleable" and provide minimal insight on similar problems.
I've seen some people who deliver applications as executables and I wanted to reproduce such outcome with Node.js, I've tried to use nexe
and pkg
tools which seem to promote outcome that I want to archive, yet when I tried to use them I constantly keep getting problem with missing .node
files from bcrypt
and realm
in my application.
In every place where I was looking for solution I was seeing that "solution" for this problem is excluding realm
and bcrypt
from JavaScript bundle as they either take too much space or are not performant, as these can be installed from npm yet the outcome wanted archive is Single Executable Application (SEA) and I do not have clue what to do next.
Node.js is runtime and JavaScript is interpreted language which means it runs code without compilation step. The problem you're trying to solve is a quite big rabbit hole that was there on table since 2013. However, just in 2022-2023 there was a additional effort done around Deno and Bun to package Node.js applications with bundled runtime.
Some runtimes (Bun and Deno) are able to ship runtime and which will run bundled code which may look as compiled application but de facto it's not - outcome may be similar for end-user as they see single file but these two are completly two different things.
I recommend trying out building code with Bun and with enough luck thing will work out but if they do not and bun will not implement fixes on their own I would risk statement that is completly impossible to do so. https://bun.sh/docs/bundler/executables
In ~2022..2023 the preferred way of doing such things was usage of pkg
yet it was archived and probably will not be longer maintained as Node.js introduced experimental support for Single Executable Applications (SEA) which means there is no longer need for tools like pkg
, same goes for nexe
and all other tools that we're used before ecosystem change to ESmodule from CommonJS and others.
Additional Resouces:
Answer was orginally posted here