Reputation: 3671
I'm learning Electron and everything I'm seeing is using the file:// protocol to load pages, and so far this is working fine. I also see some references to using Express within Electron.
My question is - is there any reason to use a web server such as Express within an Electron app? What does it get you?
Thanks.
Upvotes: 9
Views: 5839
Reputation: 1464
I was considering this since I'm making an Offline Desktop Electron app and wanted to make some reusable functions for an app that could be a new SaaS solution.
So unless you were thinking of the same, then I don't really find any good reason to have this. I'm trying to find some best practices, but I found little to none. It seems the practice was quite uncommon although totally possible. Technically, all you have to do is use the Electron as a server.
At first, I tried out ExpressJS just to make sure whether the express app could run, the only problem I had was with cors
, but things went well after that. What I can see is, that if you're planning to create a desktop app, and it was about to go complex, you should just go to your usual web library/framework tools to make it easier.
But hey, I'm open to suggestions if I made a mistake okay. I'm trying out this myself. I'll update anytime if I found the cons of it.
Upvotes: 2
Reputation: 5446
I think the scenario is pretty odd: The combination of a desktop-UI with a server-framework seems to be somewhat counter-intuitive.
What you see when file:// is referenced are (local) file system calls - these could well be calls to other protocols like http:// or ws:// instead, and do not require the Express framework to be present.
Instead, Express enables your application to receive connections from the outside and act as a server. This could be a webserver serving static or dynamic content, a REST-API endpoint or some other kind of web service endpoint.
There is indeed a project showing exactly this combination: The Express server is responsible for serving content, Electron is used to wrap a logging-UI that displays whatever is currently happening.
From an architecturial standpoint however, I would probably seperate each of these concerns into seperate standalone applications.
Upvotes: 4