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:
This sets up a package.json
file.
Next, install Electron as a development dependency:
2. Project Structure
A basic Electron project needs just a few files:
-
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:
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:
5. Running Your App
Update your package.json
scripts:
Then run:
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
Post a Comment