In this post, I will show you how to create a desktop app with HTML, CSS, and JavaScript. We will use the electron
framework to create the app. Our app will be a simple calculator. It will have a text field where you can enter the numbers, and a button to perform operations.
Contents
- What is Electron?
- Getting things ready
- Creating the app
- Developing the app
- Creating an executable file
- Conclusion
What is Electron?
Electron is a framework for building cross-platform desktop applications with web technologies like HTML, CSS, and JavaScript. It is used to create desktop apps for Mac, Windows, and Linux.
Who uses Electron?
Electron is used by a wide range of developers, from startups to large companies. Some popular apps built with Electron include Slack, Discord, Visual Studio Code, and WhatsApp.
Getting things ready
Before we start, we need to install the electron
framework. You will need to install these things.
- Node.js (Latest version) -
nodejs
- A code editor like -
Visual Studio code
Creating the app
We will create a new folder called calculator-app
. And now open the terminal in that folder. And type the following command.
The above command will create a package.json
file in the current folder. This file contains the information about the app.
Then we will install the dependencies using the following command.
Now create a file named main.js
in the calculator-app
folder, No need to put any code in this file.
Then, create a file named index.html
. This file will contain the HTML code for the app.
Now we will create a file named style.css
. This file will contain the CSS code for the app.
Now, in the main.js
file, add the following code.
Now let’s start the app. In the package.json
file, replace
it with
And also replace
with
So that we can run the app using the following command.
Yay! We have created our app. Now, here’s what we get.
Developing the app
Now that we have created the app, we can start developing it. The first thing we need to do is to hide the menu bar. We can do this by adding the following code inside the createWindow()
function.
Now the menu bar will be hidden.
Creating an executable file
Now, we have created the app. We can create an executable file using the following command.
This will install the electron-packager
package.
After installing the package, we can create an executable file using the following command.
Yay! We have created an executable file. Now, in the calculator-app
folder, there is a folder named calculator-win32-x64
. This folder contains the executable file. It’s called calculator-app-win32-x64.exe
.
Conclusion
You now know how to create a desktop app. Using Electron. Now, you can create your desktop app.
You can learn more about Electron from the following links.
Get the code - https://github.com/Posandu/create-electron-app/