I'm assuming that your main.js file is where you created your BrowserWindow(s). This is your main process and is where you would write your server side method.
In your main process you can create a method using ipcMain either asynchronously or synchronously like so:
// In main process.
const {ipcMain} = require('electron');
ipcMain.on('asynchronous-message', (event, arg) => {
console.log(arg); // prints "ping"
event.sender.send('asynchronous-reply', 'pong');
});
ipcMain.on('synchronous-message', (event, arg) => {
console.log(arg); // prints "ping"
event.returnValue = 'pong';
});
You can then call this method in a render process (js running in the chromium instance) like so:
// In renderer process (web page).
const {ipcRenderer} = require('electron');
console.log(ipcRenderer.sendSync('synchronous-message', 'ping')); // prints "pong"
ipcRenderer.on('asynchronous-reply', (event, arg) => {
console.log(arg); // prints "pong"
});
ipcRenderer.send('asynchronous-message', 'ping');
Writing a method in the js folder you show above would be part of a render process.
Hope this helps!
jsfolder, that of course depends on where you import that JavaScript. - user94559