Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS app for end-user distribution

Tags:

node.js

I'm looking for the proper way to distribute/deploy a node.js app that would run as a small webserver on the user's machine.

Is there a stub method or install script or a "install wizard" that would download all node_modules dependencies, download the latest nodejs binary, set up the environment, etc... or I have to distribute it bulk with everything packed? Is there any guide for that purpose?

like image 573
Azevedo Avatar asked Mar 05 '17 15:03

Azevedo


1 Answers

Edited :

You could install node and npm, download your dependencies by running npm install in the command line (first declare them within your package.json) only then users can run your script. This is how you do development in Node.js, or deploy to a development server. See using npm. You could automate that with a shell script if that is what you are after.

However, when distributing programs to end-users that might not be the best approach. Linux users are used to a package (.deb for instance) and Windows users are used to an .exe or a setup wizard.

That is why I recommended the tools below. I also assumed you were targeting Windows as this is less of a problem is unix-like environments.

If you want a single file (.exe), pkg and nexe are made for that purpose. These Node.js tools are used by the developer to compile JavaScript code into a single executable binary that is convenient for end-users and Windows deployment. The resulting .exe file is very light and does not require node to be installed on the end-user’s computers.

Electron along with electron-packager can produce setup wizards, but it installs a lot of files even for the smallest program. Your program will include all of node and webkit, that is why it produces heavy installs.

NSIS can also create a setup wizard, it is simple and does common stuff well (copying files, running shell scripts).


Original answer:

Short answer is: not really.

You have to keep in mind that Javascript is and has always been interpreted, so until recently never compiled to binary as you might do with other languages. Some exploration has been going on, but essentially you won’t get a "good practice" answer.

The long answer is, maybe, for some limited use cases:

  • There is the fresh new pkg that does exactly this, and it looks promising.

  • There has been nexe for a while, it works great for some use cases (maybe yours). Native/compiled modules are still an issue however.

  • Electron might work for a full blown app with a significant user interface, but it is not light or compact.

You could always use browserify to concatenate and uglify all your code with the modules you use and then make an installer with something like NSIS to setup node and your script. Native modules would still be a problem however.

like image 76
gabssnake Avatar answered Nov 14 '22 23:11

gabssnake