Exposing REST API from Electron app


#1

Hi!

I am currently in process of finding if technology stack I plan to use is a feasible solution and I have no experience with creating Electron apps so please forgive me my ignorance.

Can I expose REST API (for example using express.js) from inside of Electron app?

Scenario I want to use it for:

  • I distribute Electron app that consist of web application and also express.js server that handles connection local SQLite DB and more complicated logic
  • In said express.js server I also expose API that is accessed outside Electron app
  • User can connect to the API knowing port on which API is available and consume data

I have working solution right now by simply using Node but is not user friendly. If someone wants to use it on his machine then installation of Node is required. And also I would not be guaranteed what browser they will use to consume web page application.
It would be perfect if I could package everything inside one app and still be able to access REST API. Of course I am aware that API will available only when Electron app is running.


#2

Electron bundles Node inside it, so any scripts you have that run on Node should work exactly the same through Electron.