Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
How to Create a Desktop App Using JavaScript?
Next article icon

Introduction to ElectronJS

Last Updated : 27 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Creating cross-platform applications often requires learning multiple programming languages and frameworks. However, Electron.js eliminates this complexity by allowing developers to build desktop applications using familiar web technologies like JavaScript, HTML, and CSS.

In this article, we will learn more about ElectronJS and also see how to implement it in our projects.

What is ElectronJS?

ElectronJS is the framework through which developers can build cross-platform desktop applications using web technologies like HTML, CSS, and JavaScript. It is open-source.

  • Cross-Platform Development: We can write the code of the ElectronJs once and can deploy it in any operating system.
  • Single Codebase for All Platforms: It maintains a single codebase for all platforms which reduces the time and development costs.
  • Automatic Updates: ElectronJs provides the features of built-in support for automatic updates so developers can easily deliver updates to users, without requiring them to download and install them manually.
  • NodeJS Backend: With the help of NodeJS Electronjs allows the application to access low-level operating system features, such as reading and writing files, and making network requests.

How Does ElectronJS Work?

ElectronJS works in two processes

Main Process

The main process in the ElectronJS is responsible for communicating with the operating system and managing the lifecycle, creating and managing application windows. It is written using NodeJS and for handling the system events they interact with the renderer processes.

Renderer Process

The renderer process is essentially a web page running inside a Chromium window, rendering the user interface using web technologies (HTML, CSS, and JavaScript). Each Electron window runs its renderer process, which can be used to display various views and components of the application.

Setting Up ElectronJS

Step 1: Install NodeJS

  • Download and install NodeJS from nodejs.org.
  • Make sure npm (Node Package Manager) is installed along with NodeJS.

Step 2: Create a New Project

mkdir electron-app cd electron-app npm init -y

This will generate a basic package.json file with default values.

Electron-app

electron-app

Step 3: Install Electron

Install Electron as a development dependency using npm:

npm install electron --save-dev

Folder Structure

Folder-Structure

Folder structure

HTML
<!-- src/index.html --> <html> <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <title>Electron App</title>     <link rel="stylesheet" href="styles.css"> </head> <body>     <h1>Welcome to Electron!</h1>     <p>This is a basic Electron app.</p>     <button id="changeTextButton">Change Text</button>     <script src="renderer.js"></script> </body> </html> 
CSS
/* src/styles.css */ body {     font-family: Arial, sans-serif;     background-color: #f4f4f9;     display: flex;     justify-content: center;     align-items: center;     height: 100vh;     margin: 0; }  h1 {     color: #333; }  button {     padding: 10px 20px;     font-size: 16px;     cursor: pointer;     margin-top: 20px; } 
JavaScript
// src/main.js const { app, BrowserWindow } = require('electron'); let mainWindow;  function createWindow() {     mainWindow = new BrowserWindow({ width: 800, height: 600 });      mainWindow.loadFile('index.html');      mainWindow.on('closed', () => {         mainWindow = null;     }); }  app.on('ready', createWindow);  app.on('window-all-closed', () => {     if (process.platform !== 'darwin') {         app.quit();     } }); 
JavaScript
// src/renderer.js document.getElementById('changeTextButton').addEventListener('click', () => {     document.querySelector('h1').innerText = 'Text Changed!'; }); 

Start the app using the following command

npm start

Output

Electron-app

electron-app

Key Features of ElectronJS

  • Creating a Window with Local HTML: Instead of loading a webpage, you can load a local HTML file:
mainWindow.loadFile("index.html");
  • Adding a Custom Menu: Electron allows developers to create custom menus:
const { Menu } = require("electron");  const menuTemplate = [     {         label: "File",         submenu: [{ label: "Exit", role: "quit" }]     } ];  const menu = Menu.buildFromTemplate(menuTemplate); Menu.setApplicationMenu(menu);
  • Using System Notifications: Electron provides native desktop notifications:
const { Notification } = require("electron");  new Notification({ title: "Hello!", body: "This is an Electron notification." }).show();
  • Creating a Tray Application: Electron supports tray icons for background applications:
const { Tray } = require("electron");  const tray = new Tray("icon.png"); tray.setToolTip("Electron App");
  • File System Access: You can read/write files using Node.js:
const fs = require("fs");

fs.writeFileSync("test.txt", "Hello Electron!");

Electron vs Other Frameworks

FeatureElectron.jsNW.jsTauriFlutter Desktop
LanguageJavaScriptJavaScriptRustDart
Uses ChromiumYesYesNoNo
System API AccessYesYesYesYes
App SizeLarge (~50MB)Large (~50MB)Small (~5MB)Moderate (~10MB)
Cross-PlatformYesYesYesYes

Use Cases for ElectronJS

  • Cross-Platform Desktop Applications: Electron allows developers to create apps that can run across all operating systems.
  • Web-Based Apps: Applications like GitHub Desktop or WordPress Desktop that are essentially web-based apps but packaged as native desktop applications are great examples of how Electron can be used.
  • Development Tools: Electron is frequently used for building development tools, such as text editors (Visual Studio Code, Atom), IDEs, or version control clients.
  • Custom Dashboards: Electron is ideal for building custom dashboards, such as business or analytics dashboards that integrate with various data sources and provide real-time updates.

Limitations of ElectronJS

While Electron is powerful, it has some downsides

  • Large Application Size: Electron apps bundle Chromium + Node.js, leading to large package sizes (~50MB+).
  • High Memory Usage: Since each window runs in a separate process, RAM consumption is higher than native applications.
  • Security Concerns: Improper configurations can expose security risks like remote code execution (RCE)


Next Article
How to Create a Desktop App Using JavaScript?

A

AbhishekGarain
Improve
Article Tags :
  • JavaScript
  • Technical Scripter
  • Web Technologies
  • ElectronJS
  • Technical Scripter 2019

Similar Reads

  • Introduction to ElectronJS
    Creating cross-platform applications often requires learning multiple programming languages and frameworks. However, Electron.js eliminates this complexity by allowing developers to build desktop applications using familiar web technologies like JavaScript, HTML, and CSS. In this article, we will le
    5 min read
  • How to Create a Desktop App Using JavaScript?
    Building a JavaScript desktop application is possible using various frameworks and technologies. One popular approach is to use Electron, which is an open-source framework developed by GitHub. Electron allows you to build cross-platform desktop applications using web technologies such as HTML, CSS,
    2 min read
  • Environment Variables in ElectronJS
    ElectronJS is an Open Source Framework used for building Cross-Platform native desktop applications using web technologies such as HTML, CSS, and JavaScript which are capable of running on Windows, macOS, and Linux operating systems. It combines the Chromium engine and NodeJS into a Single Runtime.
    7 min read
  • Manage Staging Environments in ElectronJS
    ElectronJS is an Open Source Framework used for building Cross-Platform native desktop applications using web technologies such as HTML, CSS, and JavaScript which are capable of running on Windows, macOS, and Linux operating systems. It combines the Chromium engine and NodeJS into a Single Runtime.
    6 min read
  • Integrate Angular 7 with ElectronJS
    ElectronJS is an Open Source Framework used for building Cross-Platform native desktop applications using web technologies such as HTML, CSS, and JavaScript which are capable of running on Windows, macOS, and Linux operating systems. It combines the Chromium engine and NodeJS into a Single Runtime.
    8 min read
  • Command Line Arguments in ElectronJS
    ElectronJS is an Open Source Framework used for building Cross-Platform native desktop applications using web technologies such as HTML, CSS, and JavaScript which are capable of running on Windows, macOS, and Linux operating systems. It combines the Chromium engine and NodeJS into a Single Runtime.
    6 min read
  • Keyboard Shortcuts in ElectronJS
    ElectronJS is an Open Source Framework used for building Cross-Platform native desktop applications using web technologies such as HTML, CSS, and JavaScript which are capable of running on Windows, macOS, and Linux operating systems. It combines the Chromium engine and NodeJS into a Single Runtime.U
    6 min read
  • Windows Taskbar Operations in ElectronJS
    ElectronJS is an Open Source Framework used for building Cross-Platform native desktop applications using web technologies such as HTML, CSS, and JavaScript which are capable of running on Windows, macOS, and Linux operating systems. It combines the Chromium engine and NodeJS into a Single Runtime.
    6 min read
  • File Upload in ElectronJS
    ElectronJS is an Open Source Framework used for building Cross-Platform native desktop applications using web technologies such as HTML, CSS, and JavaScript which are capable of running on Windows, macOS, and Linux operating systems. It combines the Chromium engine and NodeJS into a Single Runtime.
    8 min read
  • Managing Themes in ElectronJS
    ElectronJS is an Open Source Framework used for building Cross-Platform native desktop applications using web technologies such as HTML, CSS, and JavaScript which are capable of running on Windows, macOS, and Linux operating systems. It combines the Chromium engine and NodeJS into a Single Runtime.
    9 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences