What Is Electron?

Learn how Electron works, set up your development environment, run your first desktop app, and explore the course roadmap.

🎯 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:

PartMain responsibilityCommon files
Main processManage the application lifecycle, windows, and system capabilitiesmain.js
Preload scriptExpose restricted capabilities to the pagepreload.js
Renderer processDisplay HTML, CSS, and the interactive interfaceindex.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.

Electron apps bundle Chromium and Node.js, so their packages are usually larger than ordinary web projects. Consider development efficiency, package size, and memory use when choosing a platform.

🧰 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
The Node.js installation page and command-line prompts change periodically, so your options may differ slightly. Prefer a currently supported LTS version and follow the official page and actual terminal prompts.

Set the main process entry point in package.json and add a start command:

package.json
{
    "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:

main.js
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:

index.html
<!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:

  1. What Is Electron?: Learn how it works and run your first window.
  2. Main Process, Renderer Process, and Preload Scripts: Establish process boundaries.
  3. Integrating Electron with Vue: Connect the desktop project to a real frontend project early.
  4. Window Creation and Application Lifecycle: Handle window creation, restoration, single-instance execution, and quitting.
  5. IPC and API Design: Let Vue pages safely request main process capabilities.
  6. Local Files and System Interaction: Work with files, the clipboard, notifications, and shell capabilities.
  7. Desktop Security Basics: Harden pages, navigation, and IPC boundaries.
  8. Menus, Tray Icons, and Multiple Windows: Implement common desktop interactions.
  9. Sessions, Networking, and Local Storage: Manage login state and application settings.
  10. Custom Protocols and Resource Loading: Handle deep links and packaged resources.
  11. Long-running Tasks and Performance Troubleshooting: Avoid blocking and diagnose stability problems.
  12. PDF Printing and Report Export: Deliver page content as report files.
  13. Application Packaging and Automatic Updates: Generate application directories and installers, and understand update publishing.
  14. Desktop Application Signing and Notarization: Prepare certificates, configure Forge, verify signatures, and complete macOS notarization.
  15. Testing, Monitoring, and Release: Verify critical workflows and establish release checks.
  16. 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.
  • BrowserWindow creates windows, and loadFile loads local pages.
  • electron . starts the entry point declared in package.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.