How to fork a process of another module
<p><strong><em>TL;DR : How does one fork a process that is located outside of the current running process?</em></strong></p>

<p>I'm trying to use <code>child_process</code> of Nodejs in order to start another nodejs process on the parent's process exit.</p>

<p>I successfully executed the process with the <code>exec</code> but I need the child process be independent of the parent, so the parent can exit without waiting for the child, hence I tried using <code>spawn</code> with the <code>detached: true, stdio: 'ignore'</code> option and <code>unref()</code>ing the process:</p>

<blockquote>
  <p>setting options.detached to true makes it possible for the child process to continue running after the parent exits.</p>
</blockquote>

<p><code>spawn('node MY_PATH', [], {detached: true, stdio: 'ignore'}).unref();</code></p>

<p>This yields the :</p>

<p><code>node MY_PATH ENOENT</code> error. which unfortunately I've failed resolve.</p>

<p>After having troubles achieving this with <code>spawn</code> and reading the <a href="https://nodejs.org/api/child_process.html#child_process_asynchronous_process_creation" rel="nofollow noreferrer">documentation</a>again i figured i should actually use <code>fork</code>:</p>

<blockquote>
  <p>The child_process.fork() method is a special case of child_process.spawn() used specifically to spawn new Node.js processes.</p>
</blockquote>

<p><code>fork()</code> doesnt take a command as its' first argument, but a <code>modulePath</code> which i can't seem to fit since the script I'm trying to run as a child process isnt in the directory of the current running process, but in a dependency of his.</p>

<p>Back to the starting TL;DR - how does one fork a process that is located outside of the current running process?</p>

<p>Any help would be much appreciated!</p>

<p><strong>EDIT:</strong></p>

<p>Providing a solution to the <code>spawn</code> ENOENT error could be very helpfull too!</p>