Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Demonstrates communication between renderer and main process using IPC.
// main.js
const { app, BrowserWindow, ipcMain } = require('electron');
function createWindow() {
const win = new BrowserWindow({ webPreferences: { nodeIntegration: true, contextIsolation: false } });
win.loadFile('index.html');
}
ipcMain.on('ping', (event, arg) => {
console.log(arg);
event.reply('pong', 'Hello from Main!');
});
app.whenReady().then(createWindow);
// index.html
<!DOCTYPE html>
<html>
<body>
<h3>IPC Example</h3>
<button id='btn'>Ping Main</button>
<script>
const { ipcRenderer } = require('electron');
document.getElementById('btn').addEventListener('click', () => {
ipcRenderer.send('ping', 'Ping from Renderer');
});
ipcRenderer.on('pong', (_, msg) => alert(msg));
</script>
</body>
</html>Electron is an open-source framework for building cross-platform desktop applications using web technologies (HTML, CSS, JS) with Node.js integration and Chromium-based rendering. It allows developers to create desktop apps for Windows, macOS, and Linux with a single codebase.
Origin & Creator
Created by GitHub in 2013 (originally as Atom Shell) to power the Atom text editor, Electron has grown into a popular framework for desktop apps.
Industrial Note
Best suited for cross-platform desktop apps where rapid development with web technologies is prioritized over binary size or raw performance.