How to programmatically upload an Arduino sketch generated by node.js (electron) or from browser?
There are two things you need to do:


Compile the sketch into a .HEX file
Upload the sketch to the board


The first part can be done with arduino-builder which is part of the IDE since 1.6.6, or you can use one of various Makefile projects on a platform that supports make, or you can manually script it yourself calling the correct avr-gcc and avr-g++ commands. You can check the output of the IDE for what those are.

The second part is done, usually, using avrdude - again see the output of the IDE for the correct command format.