Electron Tutorial
Learn Electron step by step: 36 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is Electron and When Should You Use It Learn what Electron is, how it bundles Chromium and Node.js into one desktop runtime, which apps use it, and the trade-offs in size, memory and security before you start.
- Setting Up Your First Electron App Install Node.js, create a project, add Electron, write main.js, index.html and package.json, and run your first desktop window with npm start. Includes runnable checks and a UI preview.
- Electron Project Structure, Scripts and Tooling Organize an Electron project into main, preload and renderer folders, choose between plain setup, Electron Forge and Vite templates, and wire dev scripts, DevTools and hot reload.
- The Electron App Lifecycle and Its Events Understand the Electron app lifecycle: ready, activate, window-all-closed, before-quit, will-quit and single-instance locking, with a runnable event-order stand-in and platform differences.
Main and Renderer Processes
- The Electron Main Process and Node.js Learn what the Electron main process does, which Node.js and Electron modules it can use, why it must never block, and how to keep it small, responsive and safe.
- The Renderer Process and Web APIs in Electron Learn what the Electron renderer process is, which web APIs it can use, why it should not have Node.js access, and how renderers differ from the main process, with runnable demos.
- BrowserWindow Options and WebPreferences Configure Electron windows with BrowserWindow options: size, position, show, backgroundColor, webPreferences, preload, sandbox, and avoid the white flash with ready-to-show.
- Electron Process Model, WebContents and Utility Processes See the full Electron process model: main, renderers, GPU and utility processes, webContents and its events, worker threads, and when to move heavy work out of the main process.
- Loading Content, Navigation and Custom Protocols Load pages in Electron with loadFile and loadURL, control navigation and new windows, open links in the default browser, and serve app files through a custom protocol.
IPC and Preload Scripts
- IPC in Electron: Channels and Messages Explained Understand inter-process communication in Electron: why renderers and the main process need IPC, the four messaging patterns, channels, serialization, and a runnable model of how it works.
- Preload Scripts and contextBridge in Electron Learn how Electron preload scripts connect pages to the main process safely: contextIsolation, contextBridge.exposeInMainWorld, a minimal API surface and common mistakes, with runnable models.
- Two-Way IPC with ipcRenderer.invoke and ipcMain.handle Build request and response IPC in Electron with ipcRenderer.invoke and ipcMain.handle: arguments, return values, errors, dialogs, file reads and a runnable mock of the page-to-main flow.
- Main-to-Renderer Messages: webContents.send and ipcRenderer.on Push events from the Electron main process to a page with webContents.send and ipcRenderer.on: menu clicks, progress updates, broadcasts to all windows and safe unsubscribing, with runnable models.
- IPC Validation, Security and Advanced Patterns Secure Electron IPC by checking senders, validating arguments, allow-listing paths, rate limiting, and use MessageChannel ports for window-to-window and streaming messages. Runnable examples.
Windows, Menus and Tray
- Electron Window Management: Multiple, Child and Modal Windows Manage Electron windows: open several windows, parent and modal dialogs, frameless windows with custom title bars, window state, multi-monitor placement, and a registry pattern. With runnable models.
- Application Menus, Accelerators and Global Shortcuts Build native application menus in Electron with Menu.buildFromTemplate, roles, accelerators, checkboxes and radio items, handle macOS differences, and register global shortcuts. Runnable template models.
- Context Menus and Native Dialogs in Electron Add right-click context menus with Menu.popup, spelling suggestions and IPC, and use native dialogs: open, save, message boxes and error boxes, with safe patterns and runnable models.
- Tray Icons, Notifications and Run-in-Background Apps Add a system tray icon with a menu, hide the window to the tray instead of quitting, show native notifications, badges and taskbar progress in Electron, with runnable state models.
Native APIs and Files
- Native Dialogs and Working with Files Open and save files in an Electron app with native dialogs and Node's fs module, keep file access in the main process, and handle errors, large files and recent documents.
- Clipboard, Notifications and the Shell Module Use Electron's clipboard, Notification and shell modules to copy text and images, show system notifications, open links safely and reveal files in the file manager.
- App Data, Paths and Persistent Settings Learn where an Electron app should store settings and data, how app.getPath works, how to build a safe JSON settings store with defaults and migrations, and how to handle corruption.
- Drag and Drop, File Associations and Deep Links Accept dropped files, start native drags out of your window, handle double-clicked documents and myapp:// deep links, and keep a single running instance in Electron.
Security Model
- The Electron Security Checklist Understand why Electron apps need a security model and apply the essentials: context isolation, sandbox, disabled Node integration, safe preload APIs and loading only trusted content.
- Navigation, Content Security Policy and Permissions Lock down what your Electron windows can load and open: block navigation, control new windows, set a strict Content Security Policy and deny unexpected permission requests.
- Validating IPC Messages and Handling Secrets Treat every IPC message as untrusted input: verify the sender frame, validate arguments with schemas, confine file paths to a folder and keep secrets out of the renderer.
- Safe Storage, Fuses and Hardening Your Build Encrypt secrets with Electron's safeStorage, flip Electron Fuses to remove risky features, understand ASAR integrity, and finish with a release hardening routine.
Packaging and Auto-update
- Packaging an Electron App with Electron Forge Turn your Electron project into a distributable app with Electron Forge: package versus make, makers, config, assets and icons, ignore rules, cross-platform limits and build scripts.
- Installers, Code Signing and Notarization Choose installer formats for Windows, macOS and Linux, understand code signing and Apple notarization, configure electron-builder, and automate signed releases in CI.
- Auto-update: Shipping New Versions to Users Understand how Electron apps update themselves: the autoUpdater events, update servers and GitHub Releases, semantic versions, staged rollouts, update UX and safe failure handling.
Testing and Performance
- Testing Electron Apps: Unit, Integration and End-to-end Build a test strategy for Electron: keep logic in plain modules, unit test with node:test, fake the electron module, test IPC handlers, and run end-to-end tests with Playwright.
- Startup Performance and Responsive Windows Make an Electron app start fast and stay responsive: measure startup, defer work, lazy-load modules, show the window at the right moment, keep the main process free and use utility processes.
- Memory, Debugging and Profiling Debug the main and renderer processes, find memory leaks with heap snapshots, log to files with rotation, capture crash reports and profile CPU use in Electron apps.
Projects and Practice
- Project: A Markdown Notes App Build a complete Electron notes app plan: project layout, secure window setup, validated IPC, a notes store with atomic saves, live Markdown preview and tests, with runnable core logic.
- Project: A Clipboard History Tool Build a clipboard history utility in Electron: poll the clipboard, deduplicate and limit entries, hide sensitive copies, search history, and paste back through a global shortcut and a tray icon.
- Project: A File Organizer with Folder Watching Build an Electron file organizer: choose a folder, watch it for new files, classify them by rules, preview a plan, move files safely with undo, and report progress to the interface.
- Electron Practice Set and Interview Questions Test what you learned with Electron practice exercises: security review, IPC design, packaging decisions, performance debugging and common interview questions with model answers.