Build Your Own Cross-Platform Desktop App.
Explore how Electron bridges the gap between web and desktop platforms — A detailed guide to build a desktop app.

Hi there 👋,
Welcome to another exciting exploration of a transformative approach to desktop application development — Electron.
📑 In this article, we’ll dive deep into the workings of Electron, revealing how this powerful framework enables you to use web technologies to create cross-platform desktop apps effortlessly. Ready to simplify your development process and extend the reach of your applications across multiple operating systems? Let’s get started! 🎊
⚛ Electron is a robust framework that enables developers to create desktop applications using web technologies like HTML, CSS, and JavaScript. It has rapidly gained popularity and is now used by many large-scale applications such as Slack, Microsoft Teams, Trello, Discord and Visual Studio Code.
The core idea behind Electron is simple yet powerful: it combines Chromium’s rendering library and the Node.js runtime, allowing developers to build cross-platform applications that run on Windows, macOS, and Linux. This approach means that you can write your application code once and run it everywhere, leveraging the vast ecosystem of web development tools and libraries.
Let’s build an app with me 🎉
#1: Initializing a New Node.js Project
The first step in building an Electron application is setting up your Node.js project environment. This involves creating a new folder for your project and initializing it with npm:
This command creates a package.json file with default values, which will manage all your project dependencies.
#2: Installing Electron
To add Electron to your project, install it as a development dependency:
This command will download Electron and integrate it with your project, allowing you to build and test your application locally.
#3: Creating Essential Files
An Electron app typically requires at least two files:
index.html: The main HTML file for your app's UI.main.js: The main JavaScript file that runs the Electron app and manages the windows.
NOTE: Please make sure to place your app icons and images into the correct path (
/img/icon.png).
#4: Configuring the Start Script
To run your application:
NOTE: We will create
preload.jsfile, If you get any error on this stage, just comment that line onmain.jsfile and run the application
#5: Styling the App using Bootstrap
For quick and appealing UI design, you can use a CSS framework. Here’s how to integrate a Bootstrap CSS from Bootswatch:
- Download your chosen CSS file from Bootswatch and save it into your project directory (
/style/bootstrap.min.css) - Import the CSS file in your
index.htmlto style the application:
#6: Enhancing Functionality with JavaScript
To interact with native elements and perform OS-level operations, Electron uses two JavaScript contexts:
- Preload Script (
preload.js): This script runs before the web page is loaded, in a privileged environment with access to Node.js APIs but in a secure manner.
- Renderer Script (
renderer.js): This script interacts with the web page directly, manipulating the DOM as needed.
Create these files and set up basic interactions, such as sending information from the preload script to the renderer script using Electron’s context bridge.
To see those changes on the app, modify index.html like this:
Now, you can run the application and see the changes how it’s beautiful 🎏
#7: Continuous Development with Electronmon
To improve the development experience by automatically restarting your app upon file changes, use electronmon:
Change your start script to use electronmon:
Now, when you run npm start, electronmon will monitor changes and reload your app, making development faster and more iterative.
Package and Distribute you Application
Option 1: Using electron-forge CLI
You’ll need to integrate Electron Forge into your Electron project. If you haven’t already installed Electron Forge, Install the CLI and add it,
This command will modify your project’s configuration to include necessary dependencies and scripts for Electron Forge. It automatically updates your package.json to use Forge's configuration and scripts.
Once Electron Forge is configured, packaging your application is straightforward. Run the following command to create a packaged version of your app that is ready for distribution:
This command instructs Electron Forge to compile your application into out folder with all its dependencies and then to create distributable formats based on the makers you’ve defined in your configuration.
Option 2: Using electron-builder
Install electron-builder:
Configure the package.json for electron-builder:
Run the build command to package your app:
This command creates platform-specific packages in the dist directory, ready for distribution.
🍃 This guide provided a comprehensive overview of building an Electron application, from initial setup through development and final packaging. With Electron, you have the power to create robust desktop applications using familiar web technologies, streamlining the development process across multiple platforms.
I appreciate you taking the time to read this article.🙌
Before you move on to explore the next article, don’t forget to give your claps 👏 for this article and share with your friends. Stay connected with me on social media. Thanks for your support and have a great rest of your day! 🎊
✍️ Vinojan Veerapathirathasan.