There are so many packaging systems for Node already, but here I am presenting another way to package your applications into a self-extracting executable that has no dependencies. Ah well, a few dependencies like the processor architecture and Linux operating system maybe, but that is all.
What Is It?
It's a modified shell script originally used to create self-extracting and -installing applications for Linux. It creates a tarball including your code, the modules it depends on, the specific node binary it uses, and appends it to a script with the command to execute your code. It is essentially a binary merge of the files, the shell script, and the tar.
This is not something new... people have used such a system in the past to deliver applications for Linux. Every time you see an obscenely large ‘.sh’ file (a shell file) that can install or execute an application without requiring any other files, know that this is the packaging system being used.
What All Can It Do?
I was hoping you would ask that... this is what it does:
Creates a single file that starts your code when executed.
Does so without requiring even node or node_modules installed on the target system.
No knowledge of any framework required, develop your code just as you normally would.
Allows you to name the process it starts. Well, it at least helps you to do so.
Allows you to have environment-specific overrides for any configuration you might want.
What Can't It Do?
It requires to be bundled for the target platform, but this is expected, isn't it?
It does not work well if the module has binary/native dependencies, for when things like node-gyp or build-essential come into the picture.
It cannot make you fly... but it can make you look smart, taking your programming skills to new heights!
Where Is It? How Do I Use It?
Here. It is a simple command. To package, run:
./selfXpackager.sh -s node-bin/launcher.sh -n selfExeSample -b node-bin/node -m mymodule/ -o dist/
And to run the package:
That easy. The repository also has a sample project for you to test it out on.
When Should I Use It?
Well, how can I comment on that, it would be for you to decide! But, I can tell you how we use it. The company I work for, Vuclip, is primarily a Java shop. Our system is quite distributed, composed of many services (I dare not say microservices, it is easy to start flame wars these days) that talk to each other. But, ever since we realized the power of Node—especially in quick new developments that we do—we've leveraged it. We have much code in the form of monitoring and mock servers, automation and code generation tools, and fault injection systems built into Node. These systems are delivered, they do their job, and are removed when no longer required.
This is where the script comes in, a no dependency delivery of a tool wherever we need it. Instead of requiring Node installed on all servers, we bundle our tool with this script and deliver it to the servers we need them on—when the job is done, they disappear without a trace.
Well, almost without a trace; it’s not some stealth tool!