🌙

Moscow (MSK):

Date: Feb. 23, 2026

Time: 01:54:39

🔆

Tokyo (JST):

Date: Feb. 23, 2026

Time: 07:54:39

How to Get Started with ElectronJS

Posted: Jan. 28, 2026

ElectronJS lets you build cross-platform desktop applications using technologies you already know: JavaScript, HTML, and CSS. Popular apps like VS Code, Slack, and Discord are built with Electron.

In this guide, we’ll walk through:

  • What Electron is
  • How it works
  • How to create your first Electron app
  • A few essential code examples

What Is ElectronJS?

Electron combines:

  • Node.js (for backend/system access)
  • Chromium (for rendering the UI)
  • JavaScript (to glue everything together)

This allows you to ship desktop apps for Windows, macOS, and Linux from a single codebase.

How Electron Works (High Level)

An Electron app has two main processes:

  • Main Process

    • Controls the app lifecycle
    • Creates windows
    • Has access to Node.js APIs
  • Renderer Process

    • Runs inside each window
    • Displays HTML/CSS
    • Similar to a browser environment

Prerequisites

Before getting started, make sure you have:

  • Node.js (v18+ recommended)
  • npm or yarn
  • Basic knowledge of JavaScript

Check Node.js:

node -v

Step 1: Create a New Project

Create a new folder and initialize a Node.js project:

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

Install Electron as a development dependency:

npm install electron --save-dev

Step 2: Project Structure

A simple Electron app might look like this:

my-electron-app/
├─ main.js
├─ index.html
├─ package.json

Step 3: Create the Main Process

Create a file called 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("window-all-closed", () => {
  if (process.platform !== "darwin") {
    app.quit();
  }
});

This file:

  • Starts Electron
  • Creates a window
  • Loads an HTML file

Step 4: Create the Renderer (UI)

Create an index.html file:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>My Electron App</title>
  </head>
  <body>
    <h1>Hello from Electron 👋</h1>
    <p>Your desktop app is running!</p>
  </body>
</html>

Step 5: Update package.json

Add a start script so you can run your app easily:

{
  "name": "my-electron-app",
  "version": "1.0.0",
  "main": "main.js",
  "scripts": {
    "start": "electron ."
  }
}

Step 6: Run the App

Start your Electron app with:

npm start

You should see a desktop window displaying your HTML 🎉

Example: Using Node.js in Electron

Electron lets you access system features using Node.js.

Example (in main.js):

const os = require("os");

console.log("Platform:", os.platform());
console.log("CPU Cores:", os.cpus().length);

This is something regular browser apps cannot do.

Example: Preload Script (Best Practice)

For security, Electron recommends using a preload script to expose safe APIs.

// preload.js
const { contextBridge } = require("electron");

contextBridge.exposeInMainWorld("api", {
  sayHello: () => "Hello from preload!"
});

Then load it in main.js:

const win = new BrowserWindow({
  webPreferences: {
    preload: __dirname + "/preload.js"
  }
});

Use it in index.html:

<script>
  console.log(window.api.sayHello());
</script>

Next Steps

Once you’re comfortable, explore:

  • IPC (inter-process communication)
  • App packaging with electron-builder
  • Security best practices
  • Auto updates and native menus

ElectronJS is a powerful way to bring web skills to the desktop world. While it’s not always the lightest solution, it shines when you want rapid development, cross-platform support, and rich UI capabilities.


Do you need an app?

Do you need an App for your project? let us create one for you!

Share this post:

© 2025 MochiiFeed