You can run your Express app very easily inside your Electron app.
All you need to do is to:
- place all the files of your Express app inside a new app folder in
your_electron_app\resources\app
- reconfigure the
app.js
file - refactor some relative pathes in your Express app
You should start your Express app before opening a new BrowserWindow and the load a new mainWindow like this:
const express = require('./express'); //your express app
app.on('ready', function() {
express();
mainWindow = new BrowserWindow({
width: 1280,
height: 720,
autoHideMenuBar: true,
useContentSize: true,
resizable: false,
});
mainWindow.loadURL('http://localhost:5000/');
mainWindow.focus();
});
Pathes in Electron don't work the same way they do in your Express app.
You have to make them all from relative to absolute pathes first.
So instead of doing this:
app.set('views', '/client/views');
app.use(express.static(/client/dist/static));
you have to do this:
app.set('views', __dirname + '/client/views');
app.use(express.static(__dirname + '/client/dist/static'));
When the electron app is build using electron-packager. The app is blank as the server is not running. i want to run my app in a different machine without having to run the server all the time (which is the point). How can i keep the server running.