3 ms·
How do you do that with Node: do you ship Node binary and all packages together with each app in one tar file? Or do you manage Node versions on the server that
by arnvald 5y ago
How do you do that with Node: do you ship Node binary and all packages together with each app in one tar file? Or do you manage Node versions on the server that runs the apps?
- xrd 5y agopkg "compiles" your app into a binary with a virtual file system inside the app. If you do a "require", the runtime rewrites that call and attempts to load the files from inside the sandbox virtual file system. You can even provide assets (like say a JS app and associated HTML, CSS) that are stored inside the app. You can then build a full app as a single binary with no extra dependencies or files. There are a few gotchas like when you need native library support in your app (if you are using a sqlite driver) and then you need to ship a .node file with your app. But, generally, it is a great solution once you get the hang of it. You compile against a specific version of node, and that runtime is included in your binary. You don't need the client to install node or choose a version, you lock that down when you build your app. I've experimented with a lot of different nodejs packaging tools, but pkg seems to work the best with the fewest surprises.