Web server inside an Electron app?

We’re developing a solution to read data from USB devices and expose the data read from USB devices to a third party web app running in a browser.

The solution I’ve planned so far is like this:

  1. We develop an Electron desktop app, which is installed on customer end user workstations and can read the data from USB devices. As far as I checked, there are node libraries for accessing USB devices and they work pretty fine.

  2. The Electron desktop app has a built in web server which is running on some port X.

  3. We provide a standard web based JS library which connects to the web server running inside the electron app on the local machine on port X. I believe there are no limits for JS to do a standard GET request to a http://localhost:X/get-my-data/

  4. The user prepares the USB device (probably ticks some buttons on the Electron desktop app) and gets the data from the USB device seamlessly in their web application.

Does it sound reasonable or is there a better solution in providing a seamless integration of data obtained from USB devices into a web application?

I’ve looked into Chrome native API for accessing USB devices, however, I run into some permission issues on my Mac and it looks like they are removing it in some not so distant future.

hey Ingus,

I have faced the same problem with you recently, and I am confused on step 2, have you finished your project?

Not sure if this is the best way, but here’s something I found on the topic. Hope it’s helpful https://github.com/frankhale/electron-with-express

This seems to be working. Here’s some more detail

I wrote a blog on this https://patarapolw.github.io/2019/07/05/server-in-electron.html.

It is also possible to put Python web server (Flask) inside Electron.

The Electron desktop app has a built in web server which is running on some port X.

It seems only if Electron desktop app run in dev mode, it will bring up a web server.
In production release, it access html/js file like open static file, no built in web server

That blog entry by @patarapolw is now at https://www.polv.cc/post/2019/07/electron-web-server