Electron

41.2.1 · active · verified Sun Apr 19

Electron is an open-source framework developed by GitHub for building cross-platform desktop applications using web technologies like JavaScript, HTML, and CSS. It embeds Chromium and Node.js into a single runtime, allowing developers to create applications that run on Windows, macOS, and Linux from a single codebase. The current stable version is 41.2.1, with frequent patch and minor updates and a steady stream of beta releases (currently v42.0.0-beta.4) indicating an active and rapid development cycle. Key differentiators include its ability to leverage existing web development skills for desktop app creation, a large ecosystem of tools and libraries, and strong community support, making it a popular choice for apps requiring native system access and rich UI capabilities.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes an Electron application, creates a main window, loads an HTML file, and sets up basic lifecycle events. It emphasizes best practices for `webPreferences` like `nodeIntegration: false` and `contextIsolation: true` for enhanced security.

import { app, BrowserWindow } from 'electron';
import path from 'path';

const createWindow = () => {
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js'),
      nodeIntegration: false, // Strongly recommended to be false for security
      contextIsolation: true // Strongly recommended to be true for security
    }
  });

  mainWindow.loadFile('index.html');
  // Open the DevTools.
  // mainWindow.webContents.openDevTools();
};

app.whenReady().then(() => {
  createWindow();

  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) createWindow();
  });
});

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') app.quit();
});

view raw JSON →