Spawn a child process in Electron
<p>I'm using Node v6.2.2 and Electron v1.2.5.</p>
<p>I have a small application that I've built on top of Electron and now I need to <code>fork</code> 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 <code>ChildProcess</code> 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 <code>spawn</code> instead but it's not working as far as I can tell.</p>
<p>Here is the code I'm using to <code>spawn</code> the process (<em>lives</em> inside the file <code>./modules/tester.js</code>):</p>
<pre class="lang-js prettyprint-override"><code>const {spawn} = require('child_process');

var child = spawn(&quot;node&quot;, [&quot;worker.js&quot;], { stdio: ['inherit', 'inherit', 'inherit', 'ipc'] });

const self = {};

self.start = () =&gt; {
    console.log(&quot;start&quot;);
    child.send(&quot;ping&quot;);
};
</code></pre>
<p>And here is the code I'm using for my <code>worker.js</code> file:</p>
<pre class="lang-js prettyprint-override"><code>process.on(&quot;message&quot;, (data) =&gt; {
    console.log(data);
    console.log(&quot;pong&quot;);
});
</code></pre>
<p>And finally this is how I'm consuming it.</p>
<pre class="lang-js prettyprint-override"><code>const {app} = require(&quot;electron&quot;);

const tester = require(&quot;./modules/tester&quot;);

app.on(&quot;ready&quot;, () =&gt; {
    tester.start();
});
</code></pre>
<p>Maybe I'm doing it wrong but I don't think so because when I'm using nodejs it seems to work just fine.</p>
<p>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.</p>