Getting Started with Electron.js: Building Your First Desktop App

 

Have you ever wished you could take your favourite website or web app and turn it into a full-fledged desktop application? That’s exactly what Electron.js lets you do! It’s a magical little framework that lets web developers like us build cross-platform desktop apps using the skills we already know—HTML, CSS, and JavaScript.

Whether you’re on Windows, macOS, or Linux, Electron opens the door to creating apps that feel right at home on your desktop. In this post, we’ll take the plunge together and build a simple but super satisfying “Hello World” desktop app. By the end, you’ll see just how easy (and fun!) it can be to bring your web projects to life on your computer.


1. Setting Up Your Environment

Before starting, make sure you have:

  • Node.js installed (check by running node -v in your terminal).

  • npm (comes with Node.js).

Then, create a new folder for your project:

mkdir my-electron-app cd my-electron-app npm init -y

This sets up a package.json file.

Next, install Electron as a development dependency:

npm install electron --save-dev

2. Project Structure

A basic Electron project needs just a few files:

my-electron-app/ ├── package.json ├── main.js └── index.html
  • main.js – This is the main process that controls your app.

  • index.html – This is the front-end interface your users will see.


3. Writing the Main Process

Create a file called main.js and add the following:

const { app, BrowserWindow } = require('electron'); function createWindow() { const win = new BrowserWindow({ width: 800, height: 600, }); win.loadFile('index.html'); } app.whenReady().then(createWindow); app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } }); app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } });

Explanation:

  • app – Controls the application lifecycle.

  • BrowserWindow – Creates a window to display HTML content.

  • loadFile('index.html') – Loads your front-end page.


4. Creating the Front-End

Create index.html with some simple content:

<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Hello Electron</title> </head> <body> <h1>Hello, Electron!</h1> <p>This is your first desktop app.</p> </body> </html>

5. Running Your App

Update your package.json scripts:

"scripts": { "start": "electron ." }

Then run:

npm start

You should see your desktop window with “Hello, Electron!”


6. Next Steps

Once you’ve mastered the basics, you can:

  • Add interactivity with JavaScript.

  • Use Node.js modules for file system operations.

  • Package your app for Windows, macOS, or Linux.


Once I got the hang of Electron, I started experimenting and building a few small projects just for fun. It was amazing to see my web skills come to life as actual desktop apps!

  • Gratify Me – I made a simple app where I could save to do lists with rewards when completed and save them locally. View this project here: Gratify Me

  • Daily Muse – Designed for musicians who sometimes get stuck deciding what song to practice. Add your songs to your personal list, then shuffle through them to get inspired and pick your next practice piece no more indecision! View this project here: Daily Muse

  • The Witchery – Finally, I built a small calendar app personalised for the ethereal people who want something more than google calendars to use.

Each project taught me something new and gave me confidence to experiment even more. If you’re just starting out, I highly recommend picking one small idea and turning it into an app, you’ll learn a ton along the way!


Comments

Popular posts from this blog

How I Found Mentors as a Lost 25-Year-Old (and You Can Too)

Leveling Up: What I Learned from Attending a Tech Event Alone

Coding my first NFC tag: A Beginners Guide