Electron interprocess communication

Last Updated: April 7, 2020

There are two types of process in electron app

(1) Main process – is run by the main controller of the electron app and manege the lifecycle of the app

(2) Render process – represent the UI window and usually this is visible. This render process is managed by the Main process

There is only one main process for your electron app but you can have many render process for your app

Inter Process Communication (IPC) is used to communicate between main process and the render process

Each one of our browser window get separate render process.

If you want send data from render process to the main process you can use ipcRenderer You can send data in two ways (sync and async)

var electron = require('electron');
var ipc = electron.ipcRenderer;

// send sync messages
// send async message
ipcRenderer.send('updataData', {x:1,y:2})

You can capture the data in main process using following code block and send reply back to the render process. You can use the ipcMain

var ipc = electron.ipcMain

// if you listen to the sync message
ipc.on('updataData', function(event, arg){
    event.returnValue = 'Update Done'

// if you listen to the async message
ipc.on('updataData', function(event, arg){
    event.reply('updataData-reply', 'Update Done')