electron
:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS
Top Related Projects
Build smaller, faster, and more secure desktop applications with a web frontend.
Call all Node.js modules directly from DOM/WebWorker and enable a new way of writing applications with all Web technologies.
Portable and lightweight cross-platform desktop application development framework
Create beautiful applications using Go
A library for building cross-platform native desktop applications with Node.js and CSS 🚀. React NodeGui : https://react.nodegui.org and Vue NodeGui: https://vue.nodegui.org
Quick Overview
Electron is an open-source framework that allows developers to build desktop applications using web technologies such as HTML, CSS, and JavaScript. It provides a runtime environment that combines Chromium (the open-source version of Google Chrome) and Node.js, enabling developers to create cross-platform desktop applications that can run on Windows, macOS, and Linux.
Pros
- Cross-Platform Compatibility: Electron allows developers to create desktop applications that can run on multiple operating systems, making it easier to reach a wider audience.
- Familiar Web Technologies: Developers can leverage their existing web development skills to build desktop applications, reducing the learning curve.
- Extensive Ecosystem: Electron has a large and active community, with a wide range of plugins and libraries available to extend its functionality.
- Native-like Experience: Electron-based applications can provide a native-like experience, with access to system-level APIs and integration with the host operating system.
Cons
- Performance Overhead: Electron-based applications can have a larger footprint and consume more system resources compared to native desktop applications, as they include the entire Chromium and Node.js runtimes.
- Security Concerns: Electron-based applications may be more vulnerable to security issues, as they rely on web technologies that can be susceptible to common web application vulnerabilities.
- Complexity for Simple Applications: For simple desktop applications, the overhead of using Electron may outweigh the benefits, and a native desktop application may be a more appropriate choice.
- Dependency on Chromium and Node.js: Electron's performance and security are heavily dependent on the underlying Chromium and Node.js versions, which can introduce compatibility issues and require regular updates.
Code Examples
Here are a few code examples demonstrating how to use Electron:
- Creating a Basic Window:
const { app, BrowserWindow } = require('electron');
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
});
win.loadFile('index.html');
}
app.whenReady().then(createWindow);
- Handling Menu and Tray:
const { app, Menu, Tray } = require('electron');
let tray = null;
app.whenReady().then(() => {
tray = new Tray('path/to/your/tray/icon.png');
const contextMenu = Menu.buildFromTemplate([
{ label: 'Item1', click: () => { console.log('item 1 clicked'); } },
{ label: 'Item2', type: 'checkbox', checked: true }
]);
tray.setToolTip('This is my application.');
tray.setContextMenu(contextMenu);
});
- Interacting with the Main and Renderer Processes:
// In the main process
const { ipcMain } = require('electron');
ipcMain.on('asynchronous-message', (event, arg) => {
console.log(arg); // prints "ping"
event.reply('asynchronous-reply', 'pong');
});
// In the renderer process
const { ipcRenderer } = require('electron');
ipcRenderer.send('asynchronous-message', 'ping');
ipcRenderer.on('asynchronous-reply', (event, arg) => {
console.log(arg); // prints "pong"
});
Getting Started
To get started with Electron, follow these steps:
- Install Node.js and npm (the Node.js package manager) on your system.
- Create a new directory for your Electron project and navigate to it in your terminal.
- Initialize a new Node.js project by running
npm init -y
. - Install the Electron package by running
npm install electron --save-dev
. - Create an
index.js
file in your project directory and add the basic Electron setup code:
const { app, BrowserWindow } = require('electron');
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
Competitor Comparisons
Build smaller, faster, and more secure desktop applications with a web frontend.
Pros of Tauri
- Smaller application size due to native OS components
- Better performance and lower resource usage
- Stronger security model with limited system access
Cons of Tauri
- Less mature ecosystem and community support
- Steeper learning curve for developers new to Rust
- Limited cross-platform UI consistency compared to Electron
Code Comparison
Electron (JavaScript):
const { app, BrowserWindow } = require('electron')
function createWindow () {
const win = new BrowserWindow({ width: 800, height: 600 })
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
Tauri (Rust):
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
fn main() {
tauri::Builder::default().run(tauri::generate_context!()).expect("error while running tauri application");
}
Both Electron and Tauri allow developers to create desktop applications using web technologies. Electron uses Chromium and Node.js, while Tauri leverages native OS components and Rust. Tauri offers smaller app sizes and better performance, but Electron has a more mature ecosystem and easier cross-platform development. The choice between them depends on project requirements and developer preferences.
Call all Node.js modules directly from DOM/WebWorker and enable a new way of writing applications with all Web technologies.
Pros of NW.js
- Better performance and lower memory usage
- Native API access without additional bindings
- Supports both Node.js and Chrome APIs simultaneously
Cons of NW.js
- Smaller community and ecosystem compared to Electron
- Less frequent updates and slower adoption of new Chromium versions
- Limited built-in features for automatic updates and packaging
Code Comparison
NW.js:
nw.Window.open('index.html', {}, function(win) {
win.maximize();
win.on('closed', function() {
// Window closed
});
});
Electron:
const { app, BrowserWindow } = require('electron');
function createWindow() {
const win = new BrowserWindow({ width: 800, height: 600 });
win.loadFile('index.html');
win.maximize();
}
app.whenReady().then(createWindow);
Both NW.js and Electron are popular frameworks for building cross-platform desktop applications using web technologies. NW.js offers better performance and direct access to native APIs, while Electron has a larger ecosystem and more frequent updates. The choice between the two depends on specific project requirements and developer preferences.
Portable and lightweight cross-platform desktop application development framework
Pros of Neutralinojs
- Significantly smaller application size due to not bundling a full browser engine
- Lower memory usage and faster startup times
- Cross-platform development with native APIs, avoiding Chromium dependencies
Cons of Neutralinojs
- Less mature ecosystem and community support compared to Electron
- Fewer built-in features and APIs, requiring more manual implementation
- Limited access to certain web technologies that Electron provides out-of-the-box
Code Comparison
Electron (main process):
const { app, BrowserWindow } = require('electron')
function createWindow () {
const win = new BrowserWindow({ width: 800, height: 600 })
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
Neutralinojs:
Neutralino.init();
Neutralino.window.create('index.html', {
width: 800,
height: 600,
maximizable: false
});
Both frameworks allow creating desktop applications using web technologies, but Neutralinojs aims for a lighter footprint and closer integration with native APIs. Electron offers a more robust set of features and better integration with web technologies, while Neutralinojs focuses on efficiency and smaller application size. The choice between the two depends on specific project requirements and resource constraints.
Create beautiful applications using Go
Pros of Wails
- Smaller application size and lower memory usage
- Native OS integration and performance
- Simpler development process, especially for Go developers
Cons of Wails
- Less mature ecosystem and community support
- Limited cross-platform UI consistency
- Fewer third-party extensions and plugins
Code Comparison
Electron (JavaScript):
const { app, BrowserWindow } = require('electron')
function createWindow () {
const win = new BrowserWindow({ width: 800, height: 600 })
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
Wails (Go):
import "github.com/wailsapp/wails/v2/pkg/runtime"
func main() {
app := wails.CreateApp(&wails.AppConfig{
Width: 800,
Height: 600,
})
app.Run()
}
Both frameworks allow developers to create desktop applications using web technologies, but they differ in their approach and underlying architecture. Electron uses Chromium and Node.js, while Wails leverages the native webview of the operating system and Go for backend logic. This results in different trade-offs regarding application size, performance, and development experience.
A library for building cross-platform native desktop applications with Node.js and CSS 🚀. React NodeGui : https://react.nodegui.org and Vue NodeGui: https://vue.nodegui.org
Pros of NodeGUI
- Significantly lower memory usage and smaller application size
- Native look and feel with better performance
- Cross-platform development using Qt framework
Cons of NodeGUI
- Smaller community and ecosystem compared to Electron
- Less mature and fewer learning resources available
- Limited to Qt widgets, which may restrict some UI design options
Code Comparison
Electron (main process):
const { app, BrowserWindow } = require('electron')
function createWindow () {
const win = new BrowserWindow({ width: 800, height: 600 })
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
NodeGUI:
const { QMainWindow, QWidget, QLabel, FlexLayout } = require("@nodegui/nodegui");
const win = new QMainWindow();
const centralWidget = new QWidget();
const label = new QLabel();
label.setText("Hello World");
const rootLayout = new FlexLayout();
centralWidget.setLayout(rootLayout);
rootLayout.addWidget(label);
win.setCentralWidget(centralWidget);
win.show();
Both frameworks allow developers to create desktop applications using web technologies, but they differ in their approach and underlying architecture. Electron uses Chromium and Node.js, while NodeGUI leverages Qt and Node.js. The code examples demonstrate the different APIs and setup processes for creating a basic window in each framework.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
:memo: Available Translations: ð¨ð³ ð§ð· ðªð¸ ð¯ðµ ð·ðº ð«ð· ðºð¸ ð©ðª. View these docs in other languages on our Crowdin project.
The Electron framework lets you write cross-platform desktop applications using JavaScript, HTML and CSS. It is based on Node.js and Chromium and is used by the Visual Studio Code and many other apps.
Follow @electronjs on Twitter for important announcements.
This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to coc@electronjs.org.
Installation
To install prebuilt Electron binaries, use npm
.
The preferred method is to install Electron as a development dependency in your
app:
npm install electron --save-dev
For more installation options and troubleshooting tips, see installation. For info on how to manage Electron versions in your apps, see Electron versioning.
Platform support
Each Electron release provides binaries for macOS, Windows, and Linux.
- macOS (Big Sur and up): Electron provides 64-bit Intel and Apple Silicon / ARM binaries for macOS.
- Windows (Windows 10 and up): Electron provides
ia32
(x86
),x64
(amd64
), andarm64
binaries for Windows. Windows on ARM support was added in Electron 5.0.8. Support for Windows 7, 8 and 8.1 was removed in Electron 23, in line with Chromium's Windows deprecation policy. - Linux: The prebuilt binaries of Electron are built on Ubuntu 20.04. They have also been verified to work on:
- Ubuntu 18.04 and newer
- Fedora 32 and newer
- Debian 10 and newer
Quick start & Electron Fiddle
Use Electron Fiddle
to build, run, and package small Electron experiments, to see code examples for all of Electron's APIs, and
to try out different versions of Electron. It's designed to make the start of your journey with
Electron easier.
Alternatively, clone and run the electron/electron-quick-start repository to see a minimal Electron app in action:
git clone https://github.com/electron/electron-quick-start
cd electron-quick-start
npm install
npm start
Resources for learning Electron
- electronjs.org/docs - All of Electron's documentation
- electron/fiddle - A tool to build, run, and package small Electron experiments
- electron/electron-quick-start - A very basic starter Electron app
- electronjs.org/community#boilerplates - Sample starter apps created by the community
Programmatic usage
Most people use Electron from the command line, but if you require electron
inside
your Node app (not your Electron app) it will return the file path to the
binary. Use this to spawn Electron from Node scripts:
const electron = require('electron')
const proc = require('node:child_process')
// will print something similar to /Users/maf/.../Electron
console.log(electron)
// spawn Electron
const child = proc.spawn(electron)
Mirrors
See the Advanced Installation Instructions to learn how to use a custom mirror.
Documentation translations
We crowdsource translations for our documentation via Crowdin. We currently accept translations for Chinese (Simplified), French, German, Japanese, Portuguese, Russian, and Spanish.
Contributing
If you are interested in reporting/fixing issues and contributing directly to the code base, please see CONTRIBUTING.md for more information on what we're looking for and how to get started.
Community
Info on reporting bugs, getting help, finding third-party tools and sample apps, and more can be found on the Community page.
License
When using Electron logos, make sure to follow OpenJS Foundation Trademark Policy.
Top Related Projects
Build smaller, faster, and more secure desktop applications with a web frontend.
Call all Node.js modules directly from DOM/WebWorker and enable a new way of writing applications with all Web technologies.
Portable and lightweight cross-platform desktop application development framework
Create beautiful applications using Go
A library for building cross-platform native desktop applications with Node.js and CSS 🚀. React NodeGui : https://react.nodegui.org and Vue NodeGui: https://vue.nodegui.org
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot