What Is Electron?
🎯 Introduction
Electron lets you build desktop apps for Windows, macOS, and Linux with HTML, CSS, and JavaScript. It bundles Chromium and Node.js so pages can render normally while accessing system capabilities through controlled boundaries.
By the end of this article, you will be able to:
- Understand which problems Electron is suited to solving.
- Explain the main differences between Electron and a regular web page.
- Create and run your first Electron window.
- Understand the course roadmap.
🧱 What is Electron?
Web pages in a browser are usually sandboxed: they cannot freely read local files, create system menus, or control desktop windows. Electron adds a Node.js-powered main process alongside the frontend page, allowing the app to use these desktop capabilities.
A basic Electron app usually has three parts:
| Part | Main responsibility | Common files |
|---|---|---|
| Main process | Manage the application lifecycle, windows, and system capabilities | main.js |
| Preload script | Expose restricted capabilities to the page | preload.js |
| Renderer process | Display HTML, CSS, and the interactive interface | index.html, renderer.js |
This structure suits projects that need desktop capabilities while reusing frontend skills, such as editors, internal tools, and cross-platform clients. If an app only displays online pages, a regular web app is usually lighter.
🧰 Prepare the development environment
The examples in this course use these versions:
- Node.js
24.x LTS - npm
11.x - Electron
44.0.0
Electron recommends developing with an LTS version of Node.js. Check your local environment first:
node -v
npm -v
Then create a project and install Electron:
mkdir electron-course
cd electron-course
npm init -y
npm install --save-dev electron@44.0.0
Set the main process entry point in package.json and add a start command:
{
"name": "electron-course",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"devDependencies": {
"electron": "44.0.0"
}
}
electron . reads package.json in the current directory and executes the file specified by main.
🛠 Create your first window
Create main.js. Once Electron finishes initializing, the main process uses BrowserWindow to create a window and load a local page:
const { app, BrowserWindow } = require('electron');
const path = require('node:path');
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
});
win.loadFile(path.join(__dirname, 'index.html'));
}
app.whenReady().then(() => {
createWindow();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
Then create the page:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self'"
/>
<title>Electron Course</title>
</head>
<body>
<h1>Hello, Electron!</h1>
<p>This is my first desktop window.</p>
</body>
</html>
Run the project:
npm start
You will see a real desktop window. It displays an HTML page, while Electron manages the window itself.
The platform check in window-all-closed follows common desktop conventions: Windows and Linux apps quit after all windows close, while macOS apps usually remain in the Dock. The next article adds macOS reactivation handling.
🧭 Course roadmap
The course has sixteen articles, progressing through application structure, feature development, security, delivery and maintenance, and a practical project:
- What Is Electron?: Learn how it works and run your first window.
- Main Process, Renderer Process, and Preload Scripts: Establish process boundaries.
- Integrating Electron with Vue: Connect the desktop project to a real frontend project early.
- Window Creation and Application Lifecycle: Handle window creation, restoration, single-instance execution, and quitting.
- IPC and API Design: Let Vue pages safely request main process capabilities.
- Local Files and System Interaction: Work with files, the clipboard, notifications, and shell capabilities.
- Desktop Security Basics: Harden pages, navigation, and IPC boundaries.
- Menus, Tray Icons, and Multiple Windows: Implement common desktop interactions.
- Sessions, Networking, and Local Storage: Manage login state and application settings.
- Custom Protocols and Resource Loading: Handle deep links and packaged resources.
- Long-running Tasks and Performance Troubleshooting: Avoid blocking and diagnose stability problems.
- PDF Printing and Report Export: Deliver page content as report files.
- Application Packaging and Automatic Updates: Generate application directories and installers, and understand update publishing.
- Desktop Application Signing and Notarization: Prepare certificates, configure Forge, verify signatures, and complete macOS notarization.
- Testing, Monitoring, and Release: Verify critical workflows and establish release checks.
- Project: A Desktop Document Manager: Connect file import, integration testing, status feedback, and report saving.
🧾 Summary
- Electron uses Chromium to render pages and Node.js to provide desktop capabilities.
- The main process manages the app and windows; the renderer handles the page interface.
- Electron suits projects that need desktop capabilities while reusing frontend technology.
BrowserWindowcreates windows, andloadFileloads local pages.electron .starts the entry point declared inpackage.json.
❓ Questions and answers
Q1: Do users need to install Node.js before running an Electron app?
No. A packaged app includes the Node.js and Chromium runtimes it needs. A separate Node.js installation is needed only for local development and building.
Q2: Can Electron use Vue directly?
Yes. Vue handles pages in the renderer process, while Electron handles desktop windows and system capabilities. The course explains the core structure with plain JavaScript first; the same approach applies when Vue is added.
Q3: Why not use Node.js APIs directly in HTML?
Untrusted input can affect page content, and exposing Node.js APIs directly increases security risks. A common approach is to expose only the capabilities the page needs through a preload script.
Q4: Why doesn't closing the last window quit the app on macOS?
This follows common macOS conventions. The app keeps running and can recreate a window when the user clicks its Dock icon.
🧪 Practice
Exercise 1: Set the window width to 960, its height to 640, and add a title:
const win = new BrowserWindow({
// Write your code here
});
Exercise 2: Add a button labeled “Start learning” to index.html:
<body>
<h1>Hello, Electron!</h1>
<!-- Write your code here -->
</body>
🎉 You have run your first Electron desktop app! Next, we will examine its process structure and clarify each file's responsibilities.
Logging and Alerts
Learn frontend log levels and collection patterns, and design simple alert rules to detect problems promptly.
Main Process, Renderer Process, and Preload Scripts
Understand the roles of the main process, renderer process, and preload scripts as a foundation for Vue integration and safe IPC.
