electron communicate between renderer to nodejs code example
Example 1: electron communicate between main and renderer
const { ipcMain } = require('electron')
ipcMain.on('asynchronous-message', (event, arg) => {
console.log(arg)
event.reply('asynchronous-reply', 'pong')
})
ipcMain.on('synchronous-message', (event, arg) => {
console.log(arg)
event.returnValue = 'pong'
})
Copy
Example 2: electron communicate between main and renderer
const { ipcRenderer } = require('electron')
console.log(ipcRenderer.sendSync('synchronous-message', 'ping'))
ipcRenderer.on('asynchronous-reply', (event, arg) => {
console.log(arg)
})
ipcRenderer.send('asynchronous-message', 'ping')
Copy