'Angular + Express.js app in Electron doesn't starts
I have successfully managed to build MEAN App. Now i want that app to run inside electron. The following command is working on web browser
"electron-build": "ng build && node ./bin/www"
But when i tried this code
"electron-build": "ng build && electron . && node ./bin/www"
The build is successful and the app runs in electron but the server is not running & when i quit the electron app from GUI i got the successful connection log in console.
Now when i tried this code
"electron-build": "ng build && node ./bin/www && electron ."
The server starts successfully but the electron app doesn't rendered.
Solution 1:[1]
Problem is that two process (node ./bin/www and electron.) can't be execute in same Thread.
You can do some like that
const { app, BrowserWindow } = require('electron')
const path = require('path');
function createWindow () {
win2 = new BrowserWindow({ width: 800, height: 600 })
win2.loadURL(
path.join('file://', __dirname, '/index.html')
);
}
app.on('ready', createWindow)
And in index.html add the tag with you server.js or app.js (file with code of node/express). Like:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Simple Mouse Control - Server</title>
<script src="server.js"></script>
</head>
<body>
Hola
</body>
</html>
And finally:
"electron-build": "ng build && electron ."
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | German Burgardt |
