question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running express server as part of electron app

See original GitHub issue

I have a server electron app to which all client apps connect. I had to do this because the customer wants the server running within their premises. I created an express server in the following way:-

  1. Created a server.js file inside public directory where I run the express server.
  2. Created a server.html which is loaded in a new hidden browser window from electron.js. The server.html simply runs a function with require('.\server'). I get an error here saying that the required module was not found. I don’t know why since server.html and server.js are right next to each other. %PUBLIC_URL% won’t work here since server.html is loaded after the build step and during the electron step.

What can I do to fix this issue? Is there a better way of running an express server with create-react-app for electron?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
csepulvcommented, Sep 12, 2017

I think you need to run the express server on its, not from within the electron application. You can use node-foreman to help setup multiple processes in development, but basically you need to manage/develop your server as its own application.

0reactions
ZoeDreamscommented, Sep 18, 2017

@nikhilag right, that makes sense if you use electron as a wrapper application to your server, Even though i still would try to avoid smashing your server code directly into the electron app. Having a thin client to handle auto-updating and settings is a great idea. Many games use this architecture to handle auto-updating… IE just uses electron to download a zip or tar, and have some scripts to call the server from the CLI. Something more fancy would be using sockets to connect your electron to your server…

As far as networking and stuff, that really is up to how the firewalls are. Technically you could even configure stuff to use port 80 which most firewalls have open.

As for load, if you dig into the code and read a bunch of comments you will find that calling native file system and other functionality can be hacky. It also adds alot of overhead and makes stuff run wonky… This is another argument to use an API w/ CLI or API with sockets.

anyways thats just my opinion from experience… GLHF

Read more comments on GitHub >

github_iconTop Results From Across the Web

frankhale/electron-with-express: A simple app that ... - GitHub
A simple project demonstrating how to spawn an Express app from Electron as well as providing server logs directly in the Electron app....
Read more >
Create a Node.js desktop application with Electron, Bootstrap ...
In this tutorial, we will discover developing Node.js desktop applications with Electron, Bootstrap, and Express.js.
Read more >
Electron JS + React JS + Express JS | by Keshav Agrawal
Started working on PyQT Web Engine — lot of hiccups but worked. Now I needed a backend server running to which frontend will...
Read more >
Launch Express server from an Electron app - Erik Martín Jordán
Run the app ... Electron will open a window with "Application Electron and Express" as a title. The Express server will run on...
Read more >
NodeJS Electron with express - Stack Overflow
routes.js'); const app = express(); const publicPath ... iconPath // 'node-integration': false // otherwise various client-side things may ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found