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'));
No, absolutely not, the Node.js functionality works well, but one thing you must know is: all of the JavasScript code written in a Electron app will work properly with Node.js even using a server to load the initial file and handling requests, but if you just has tried to using Node.js functionality in AngularJS templates so you will have problems, of course, because AngularJS templates will be compiled by AngularJS and the same with others engines and AngularJS and others Front-End Template engines don't know Node.js code, so if you want to use some data generated by Node.JS in html templates you will must use a template engine like AngularJS provides one, then you will need to bind the data in variable scope and then use it in AngularJS template in question (AngularJS template case), I did tests with only AngularJS templates and using the variable scope binding aproach i could work nicely.
$scope.nodeVersion = process.versions.node
and
<p>{{ nodeVersion ]}</p>
then
6.9.1