Released · improving
Framework · Since 2013
Electron is an open-source framework for building desktop apps for Windows, macOS, and Linux with JavaScript, HTML, and CSS.
Electron is an open-source framework for building desktop applications with web technologies. It bundles Chromium for rendering and Node.js for operating system access into a single runtime, so one codebase can ship as an app for Windows, macOS, and Linux. It began at GitHub in 2013 as Atom Shell, the foundation of the Atom editor, and is now a project of the OpenJS Foundation.
Electron shines when a team that already knows the web needs a desktop app quickly. It powers the desktop versions of Visual Studio Code, Slack, and Discord, and it lets you reuse web frameworks such as React or Vue along with the whole npm ecosystem. Because every app ships its own copy of Chromium, installers and memory usage tend to be larger, which is worth weighing up front.
To get started, install Node.js and either scaffold a project with Electron Forge or add the electron package to an empty project. The official tutorial walks through the main process, preload scripts, and renderer, and how they talk to each other over IPC. Electron Fiddle lets you run small experiments without setting up a project, which is a quick way to explore the APIs.
Chromium renders your HTML and CSS, while the main process uses Node.js to reach the file system, network, and other operating system features.
The same JavaScript or TypeScript code becomes an app for Windows, macOS, and Linux, packaged as each platform's native installer.
Windows, menus, tray icons, notifications, file dialogs, the clipboard, and auto-updates are all available as JavaScript APIs.
Main and renderer processes are separated, and context isolation with preload scripts exposes only the capabilities your UI actually needs.
Electron is installed and run through Node.js and npm. Install a Node.js LTS release and confirm that both versions print.
node -v && npm -vCreate a package.json in a new folder and install electron as a dev dependency. Then set the main field in package.json to main.js and add a start script that runs electron .
mkdir my-electron-app && cd my-electron-app && npm init -y && npm install --save-dev electronFor a project that already includes packaging and publishing, use the scaffolding command from Electron Forge, the official tooling. Run npm start inside the generated folder.
npm init electron-app@latest my-appmain.js is the entry point of the main process. Once the app is ready it creates an 800×600 BrowserWindow and loads index.html from the same folder. On macOS, apps conventionally stay running after the last window closes, so the app only quits on other platforms. Put a simple index.html next to main.js and run npm start.
main.js
const { app, BrowserWindow } = require('electron')
function createWindow() {
const win = new BrowserWindow({ width: 800, height: 600 })
win.loadFile('index.html')
}
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})
npm init -y
npm install --save-dev electron
npm pkg set main=main.js scripts.start="electron ."
npm startSix chapters that take you from installation to the core ideas of Electron.
Ask questions, share experience and trade opinions about Electron.
No discussions yet. Start the first one.
0 comments
Sign in · Sign in to leave a comment.
Be the first to comment.