Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 36 ยท 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.

Electron is a framework for building desktop applications with JavaScript, HTML and CSS. You write one codebase, and Electron turns it into a native-feeling app for Windows, macOS and Linux: it has its own window, an icon in the dock or taskbar, menus, notifications and access to the file system. If you have ever used a chat app, a code editor or a note-taking tool that looked suspiciously like a website in a frame, there is a good chance you were using Electron.

This lesson explains what is inside Electron, why teams choose it, and where it is a poor fit. You do not need to install anything yet. Since the real Electron runtime cannot run on this site, the examples here are plain JavaScript stand-ins that model the ideas, and the real Electron code is shown in read-only blocks.

The big idea: a browser and a server in one box

An Electron app is made of three ingredients that ship together:

  • Chromium, the open-source engine behind Google Chrome. It draws your HTML, runs your CSS and executes your front-end JavaScript.
  • Node.js, the JavaScript runtime used on servers. It gives your app access to files, processes, networking and the operating system.
  • Electron's own APIs, a library of modules that wrap native features: windows, menus, dialogs, tray icons, notifications, auto-update and more.

Because you ship the whole runtime inside your app, you control exactly which browser version and Node.js version your code runs on. A web page has to work in whatever browser the visitor has. An Electron app only has to work in the Chromium you bundled.

What is inside an Electron app

Chromium Renders your UI
Node.js Files, processes, network
Electron APIs Windows, menus, tray
Your code HTML, CSS, JavaScript

Everything ships together in one installer.

1 / 2

Apps built with Electron

Many well-known tools are Electron apps: editors such as Visual Studio Code, communication tools such as Slack, Discord and Microsoft Teams, note-taking apps, design tools and API clients. They share a pattern: a rich interface, frequent updates, and a team that already knows the web. We name them only to show the range; you do not need to know how any of them work internally.

How an Electron app is organized

Every Electron app has exactly one main process and zero or more renderer processes. The main process is a Node.js program that starts first. It creates windows, and each window runs its own renderer process, which is basically a tab of Chromium showing your page. A third piece, the preload script, runs inside the renderer before the page and acts as a controlled bridge between the two worlds. The next chapters cover each one in detail; for now, look at the shape:

flowchart LR
  M["Main process<br/>(Node.js, one per app)"] -->|creates| W1["Window 1<br/>renderer"]
  M -->|creates| W2["Window 2<br/>renderer"]
  P1["Preload script"] --- W1
  P2["Preload script"] --- W2
  W1 <-->|IPC| M
  W2 <-->|IPC| M

Figure: one main process owns many windows; renderers talk to it over IPC (inter-process communication).

A tiny model of the idea

The real Electron code to open a window is only a few lines. Here it is, read-only, so you can see how small the entry point is:

JavaScript
// main.js (runs in the real Electron)
const { app, BrowserWindow } = require('electron')

function createWindow() {
  const win = new BrowserWindow({ width: 800, height: 600 })
  win.loadFile('index.html')
}

app.whenReady().then(createWindow)

You cannot run that here, but you can run a stand-in that behaves the same way. The stand-in below defines a tiny app and BrowserWindow and prints what the real ones would do. It is not Electron; it exists so you can watch the order of events.

Node.js Stand-in: app, ready and a window

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Notice that the handler is registered before ready fires. In real Electron you must not create windows before the ready event, because the native machinery is not initialized yet.

Pros and cons

Advantage Cost
One codebase for three operating systems Installers are large (often 80 to 150 MB) because Chromium is included
Reuse HTML, CSS, JavaScript and npm packages Higher memory use than a native app
Consistent rendering: you pick the browser version You must ship security updates by releasing new versions
Mature tooling for packaging and auto-update Startup is slower than a small native binary
Full access to the OS through Node.js A careless setup can expose your user's computer (see the security chapter)

Electron is a good choice when you already have web skills, need desktop features such as file access or a system tray, and care about shipping on all platforms quickly. It is a weaker choice for tiny utilities where a 100 MB download feels absurd, or for apps that must squeeze every megabyte of RAM.

Electron versus the alternatives

  • A plain website or PWA needs no installation, but it cannot freely read your files, run background processes or integrate deeply with the OS.
  • Native toolkits (Swing, WPF, Cocoa, Qt) give the best performance and platform feel but require separate skills per platform or a heavier cross-platform learning curve.
  • Webview-based frameworks such as Tauri use the system's own web view instead of bundling Chromium, producing smaller apps at the cost of inconsistent rendering across platforms.

None of these is "best". Pick by team skills, app size budget and how much control over the rendering engine you need.

What you will build in this course

You will start with a window, learn how the main and renderer processes divide work, connect them safely with preload scripts and IPC, then add menus, tray icons and dialogs. Later chapters cover native files, security, packaging and testing. Keep one rule in mind from the start: treat your renderer like a website you do not fully trust. The pages that follow show how to do that.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What are the main building blocks bundled inside an Electron app?

    Electron ships its own copy of Chromium and Node.js together with APIs for windows, menus, dialogs and more.
  2. 2. How many main processes does an Electron app have?

    There is a single main process that starts first and creates every window; each window then has its own renderer process.
  3. 3. Which is a real cost of choosing Electron?

    Bundling Chromium and Node.js makes installers large and memory use higher, which is the usual trade-off.
  4. 4. Why does the stand-in code wait for the ready event before creating a window?

    In real Electron, BrowserWindow must not be created before app is ready, so you create windows inside whenReady.

Summary

  • Electron = Chromium + Node.js + Electron APIs, shipped with your code.
  • One main process (Node.js) creates windows; each window runs a renderer process.
  • You get one codebase for Windows, macOS and Linux, at the cost of size and memory.
  • Create windows only after the app is ready.
  • Treat the renderer like a web page that may run untrusted content.

Next: Setting Up Your First Electron App