Thought i’d make a simple Electron hello world tutorial application. Electron is a framework for building desktop apps with CSS, Javascript and HTML. The apps will be cross platform and work on Windows, MacOS and Linux distributions.
You can download this application from Github if you’d like. After this blog post was written i decided to rebrand it to the electron tutorial app because that name suits it better when adding more electron tutorials to it.
An electron app is built using the node.js framework and is brought to us by Github. Maybe you’ve already tested a few electron apps now. For example slack is a well know application built on electron. If you’d like to test one i can recommend Atom. In fact, why don’t you try this tutorial with that IDE?
Video introduction
1. Installing Node.js
First we need to install node.js. So go ahead and do that.
2. Installing electron prebuilt
Now that we have Node.js installed, let’s install electron prebuilt globally.
This makes us able to test run our electron application by running this command in our terminal. But more on this later.
2. File structure
In its most basic form an electron app needs three files. package.json, main.js, and index.html. Making the folder structure look like this:
electron-hello-world/
- index.html
- main.js
- package.json
Create a folder and add those files and let’s walk trough them one by one.
3. package.json
Let’s add content to package.json. We need a name, a version and a main setting that points to a script that will handle the starting up of the app. If main is not present electron will look for a file called index.js.
4. Main.js
As mentioned above the we pointed out main.js to handle the startup of our application. Lets add this content to it. This code is borrowed from electron quick start.
5. index.html
The index.html takes care of the gui.
6. Running the Electron hello world app
Now let’s get back to the electron . command. That will start electron and run the app that we are currently building.
This fires up an app looking like this:
As you can see we also have the chromium developer tool window opened inside our app. This is opened with this call in main.js.
7. Read more
Next tutorial covers testing your electron app in Ubuntu. If you are not interested in testing it in Ubuntu the next tutorial after that is Electron app navigation.
Read more about electron at the official site, and check out the API.