I have been able to successfully run express within the electron app via repositories such as
https://github.com/theallmightyjohnmanning/electron-express
https://github.com/frankhale/electron-with-express
However, I was advised not to do so due to the GNU GENERAL PUBLIC LICENSE that they impose. I am trying to create a commercial app that will monetize. Hence, a liscene like MIT might do, but not sure about GNU.
Anyhow, I have been trying to follow his procedure: https://gist.github.com/maximilian-ruppert/a446a7ee87838a62099d
But is running into some issues. Heres what I have done so far.
# Clone the Quick Start repository
$ git clone https://github.com/electron/electron-quick-start
# Go into the repository
$ cd electron-quick-start
# Install the dependencies and run
$ npm install && npm start
Then to get express
$ express myapp
$ cd myapp
$ npm install
renamed myapp to just app
and now I am stuck at the part where i need to configure the electron main.js
file or/and the render index.html
file to link to the express app and have that run instead of the index.html
Any help would be appreciated.
I am running on windows 10.
Packaging an Express Application in Electron
Firstly install electron in your app
Create an index.html file which contains your express application
We need a top level file which will load in our express application. If you are not using a module bundler like Webpack then simply import all the html, cs and js files that your app is dependent on into this index.html file.
Make sure that this index.html files imports everything you need for your app to run -i.e all the necessary html, css, js and other files. Remember to include any external files that your app needs such as jQuery which we loaded in the example above.
An Aside - Packaging an Electron app that uses Webpack
In this example our entire Express app is represented by a Webpack bundle which is loaded by index.html.
Remember that you don't need to use Webpack to package Express apps with Electron. Just make sure that index.html loads in all the files you need that will launch your express application.
If you are using Webpack your bundle should be imported in this index.html file.
Here is an example index.html file that imports the webpack bundle which contains our express app.
Now create the electron config file in your project root that loads the index.html containing your Express app
Here is the main file that electron will use to launch itself. Al electron related configuration and the link to our express app (through importing the Webpack bundle) is contained here.
Note the file below belongs in our root project directory and is comprised mainly of boilerplate from the Electron quick start guide with the exception of the line explained above that imports our index.html file which loads the entire application.
main.js
The following line loads our index.html we created earlier which points our electron instance to the entry point of our application.
Change the start script in your package.json to launch electron
Now when we run
Electron will automatically look for and run the main.js file in our project root.