Do I use ipcRenderer or ipcMain in Node-side helper modules?


I have a CommonJS module which contains a function that handles a HTTP request for me and builds the object I want from the JSON response.

I’m confused as to how to use it, though. It’s not going inside a BrowserWindow, so ipcRenderer seems inappropriate to use. Yet the module isn’t the Main module, so I shouldn’t use ipcMain there either. How should I send data from CommonJS modules back into Main?


In your case, you’d probably want to use a plain old Node EventEmitter:

In your main:

'use strict';

const helperModule = require('helper-module');'finished', (data) => {
  console.log ('got some data:', data);

In your helper module:

'use strict';

const EventEmitter = require('events'); = new EventEmitter();

// do things here...'finished', someAwesomeData);