How to Create a Mini Project with Electron.js
Create graphical applications for Desktop!
Electron (formerly known as Atom Shell) is a free and open-source software framework developed and maintained by OpenJS Foundation.
The framework is designed to create desktop applications using web technologies (mainly HTML, CSS and JavaScript, although other technologies such as front-end frameworks and WebAssembly are possible) that are rendered using a version of the browser engine Chromium and a back finish using the Node.js execution environment.
It also uses several APIs to enable features such as native integration with Node.js services and an inter-process communication module.
Electron was originally built for Atom and is the main GUI framework behind several open source projects, including Atom, GitHub Desktop, Light Table, Visual Studio Code, WordPress Desktop and Eclipse Theia.
Dependencies
Download directly from the website using the links below or use your operating system’s package manager.
Example of installing dependencies on Ubuntu:
Creating a basic Window
Let’s create the most basic example possible!
01. Create a folder and enter it:
02. Create a file named: package.json
:
And insert the content below:
This step can be replaced by the command:
npm init
with edits as you wish!
03. Install Electron to be added to your project:
Note that your
package.json
has been changed and added Electron support!
04. Create a file named: index.html
And insert the content below into the file:
05. Create a file named: main.js
And insert the content below into the file:
In the example below, a window with a resolution of 1280x720 is created.
06. Create the preload.js
file
And insert the content below into the file:
07. Now just run the project
When you open the window you can even access the console with: Ctrl + Shift + i
.
Example of the App we created running in the image below:
Click on the image to see in a higher resolution!
For more information access:
Comments