From your comments under the question, it sounds like you don't want it to be synchronous, and that you don't care about its output.
If you just want to fire the other process and forget, without watching it or caring about when it ends, what you're already using (spawn
) does that.
If you want to truly fire-and-forget, you'll want to specify the detached
option, so that the child process doesn't get killed when your process terminates. From the docs:
If the detached
option is set, the child process will be made the leader of a new process group. This makes it possible for the child to continue running after the parent exits.
Looking further down, apparently you have to unref
it as well:
By default, the parent will wait for the detached child to exit. To prevent the parent from waiting for a given child, use the child.unref()
method, and the parent's event loop will not include the child in its reference count.
And apparently deal with stdio
:
When using the detached
option to start a long-running process, the process will not stay running in the background unless it is provided with a stdio
configuration that is not connected to the parent. If the parent's stdio is inherited, the child will remain attached to the controlling terminal.
So:
spawn('node', ['./file.js'], {
detached: true,
stdio: [ 'ignore', 'ignore', 'ignore' ]
}).unref();