Lesson 28 of 28
javascriptInter‑process Communication (IPC)
12 mins
Course progress100%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 28 of 28
javascript12 mins
Keep these ideas in mind as you work through the lesson.
Electron ships two IPC modules:
preload/bridge.js
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('api', {
getAppVersion: () => ipcRenderer.invoke('app:getVersion')
});
main.js
const { ipcMain, app } = require('electron');
ipcMain.handle('app:getVersion', () => app.getVersion());
renderer.js (runs in the page)
document.getElementById('ver').innerText = window.api.getAppVersion();
// renderer
window.api.send('log', 'User clicked button');
// main
ipcMain.on('log', (e, msg) => console.log('[Renderer]', msg));
Use invoke/handle for request‑response (Promise‑based) and send/on for one‑way messages.