A simple project demonstrating how to spawn an Express app from Electron as well as providing server logs directly in the Electron app.
Express App:
Press 'F1' to show the server log:
Before start: Please note that this approach is intended to use in windows platform, any other OS approach would need some changes, contributions are very welcome
We'll need a copy of the Node.exe
and Node.lib
: https://nodejs.org/dist/v7.2.1/win-x64/
After downloading a copy of this repository place them in the root of the code folder. When the Electron app starts it will spawn the Express app using an external copy of Node. This allows the Express app to run outside the Electron process.
Here is a screenshot of the file layout:
The express-app
folder is just a vanilla Express generated app using
express-generator
.
- Clone the code repository.
- Open terminal to code repository.
- Make sure a copy of
Node.exe
andNode.lib
are copied to the root of the code repository. - Run
npm install
. (See Dependencies above) - Change directories to the express-app folder and run
npm install
. - Change directories back to the root of the code repository.
- Run
npm start
to start the application.
If you would like to package this using electron-packager
you'll need to
make the following change:
In index.html (line ~59):
app = require('electron').remote.app,
node = spawn(".\\node.exe", ["./express-app/bin/www"], { cwd: app.getAppPath() })
This makes sure the path to our local copy of node.exe
is correct when we run
electron to start the app.
That said, I'm assuming the platform is Windows. If other platforms are desirable additional changes are required.
Frank Hale <[email protected]>
8 December 2016
GNU GPL v3 - see LICENSE