title: Run main process as child_process
body: <p>I am having troubles with getting <code>child_process</code> working with Atom Electron. First of all, I am using the pre-compiled binary app that you can download from Electron's website:</p>
  
  <ul>
  <li>I am using the usual pre-compiled binary on Mac OS X.</li>
  <li>In <code>myapp.app/Contents/Resources</code> I made a folder app as described.</li>
  <li>I added a brief <code>package.json</code> inside it, setting <code>index.js</code> as main script.</li>
  </ul>
  
  <p>Now, if I add to <code>index.js</code> the following snippet:</p>
  
  <pre><code>'use strict';
  
  var electron = require('electron');
  var app = electron.app;
  
  const BrowserWindow = electron.BrowserWindow;
  
  var mainWindow;
  
  function createWindow () {
    mainWindow = new BrowserWindow({width: 800, height: 600});
    mainWindow.loadURL('file://' + __dirname + '/index.html');
    mainWindow.webContents.openDevTools();
    mainWindow.on('closed', function()
    {
      mainWindow = null;
    });
  }
  
  app.on('ready', createWindow);
  
  app.on('window-all-closed', function () {
    if (process.platform !== 'darwin')
    {
      app.quit();
    }
  });
  
  app.on('activate', function () {
    if (mainWindow === null)
    {
      createWindow();
    }
  });
  </code></pre>
  
  <p>(that is basically the example code to get things working) everything works fine. I get the window and I can get it to do basically anything.</p>
  
  <p>Now, for reasons related to updates, I am in need to slightly change this paradigm. What I would need is to be able to perform several tasks from <code>index.js</code> <strong>without any need to do any gui operation</strong> (it should be some sort of daemon) and then to start some <code>child.js</code> script as a <code>child_process</code> from <code>index.js</code>. <code>child.js</code> should be able to open windows and all the rest.</p>
  
  <p>So here was my naive try. I just cut and pasted the example snippet above in <code>child.js</code>, then edited <code>index.js</code> into the following:</p>
  
  <pre><code>var child_process = require('child_process');
  var my_child = child_process.fork(__dirname + '/child.js');
  </code></pre>
  
  <p>Quite minimal, right? Hoped it would work, but it didn't. When I double click on my pretty app, nothing happens. I bet I am doing something wrong in a trivial way, but I wouldn't be able to tell what.</p>
  
  <p><strong>Update 1</strong> I moved this out of my package so that I could get <code>console.log</code>s. <code>child.js</code> dies with an error at <code>require('electron')</code>: it doesn't seem to be able to find it.</p>
  
  <p><strong>Update 2</strong>: I listed the environment variables in <code>child.js</code> and noticed a <code>ATOM_SHELL_INTERNAL_RUN_AS_NODE = 1</code>. I thought I should turn that to <code>0</code>, but nothing changed.</p>