I'm using Node v6.2.2 and Electron v1.2.5.
I have a small application that I've built on top of Electron and now I need to fork
the process to run some long running task in another node process but it doesn't seems to work, when I'm looking at the ChildProcess
object I can see that in the argument spawnargs[0] is initialized with the electron executable instead of node so what I did is I've tried to use spawn
instead but it's not working as far as I can tell.
Here is the code I'm using to spawn
the process (lives inside the file ./modules/tester.js
):
const {spawn} = require('child_process');
var child = spawn("node", ["worker.js"], { stdio: ['inherit', 'inherit', 'inherit', 'ipc'] });
const self = {};
self.start = () => {
console.log("start");
child.send("ping");
};
And here is the code I'm using for my worker.js
file:
process.on("message", (data) => {
console.log(data);
console.log("pong");
});
And finally this is how I'm consuming it.
const {app} = require("electron");
const tester = require("./modules/tester");
app.on("ready", () => {
tester.start();
});
Maybe I'm doing it wrong but I don't think so because when I'm using nodejs it seems to work just fine.
I've tried many examples but none of them seems to work, another possibility is that I need to do something special in Electron for it to work but I don't know.