Create an Electron app from any web server in any programming language.
As Electron is actually an containerized extended Chromium web engine, I reckon that this must be possible somehow. However, by default, Electron uses
ipcRenderer rather than
As for a lazy reader, you can see my example project at https://github.com/patarapolw/rep2recall-sqlite, which is Python Flask in Electron. There is also a pure TypeScript version -- https://github.com/patarapolw/e-rep2recall
Finding a random PORT
You might use https://www.random.org/integers/?num=1&min=5001&max=49151&col=5&base=10&format=html&rnd=new. Just make sure you don't use too common a port number.
Containerizing web server
For Java/Kotlin/other JVM languages, you might use https://github.com/johnrengelman/shadow, i.e. fat JAR, shadow JAR, uber JAR.
__dirname for everything, and avoid hidden imports. For Express.js, at least
ejs templating engine works, but make sure to use
ejs.renderFile(). You can avoid this altogether, though, by making use of static files.
Starting web server at app start, and killing web server at app exit, including on errors
To kill on error, you might try doing a cleanup action just before node.js exits
Have only tried
socket.io. Never tried
websocket directly yet, though.
This allows you to run Electron in your default web browser in development mode using two terminal,
webpack-dev-server, and another running your default web server. Make sure to hide Electron specific code on development, though; otherwise it will throw an error in Webpack and in web browser.
Electron builder, and file associations
This might give you some ideas -- https://github.com/patarapolw/rep2recall-sqlite/blob/master/package.json#L61
asarUnpack is needed for Python and static files. -- https://github.com/patarapolw/rep2recall-sqlite/blob/master/package.json#L86.