Skip to main content
100%

Daemonize a node process

✓ Published0🌍 Public
Aalessioalex
Last edited Aug 1, 2013
Created on Aug 1, 2013

This example shows how to daemonize a Node.js process by re-spawning it in a new session with the `IS_DAEMONIC` environment variable set. It uses the `child_process.spawn` API to launch `/bin/sh` with a command that runs `setsid` on the original script, redirecting output to `/dev/null` and detaching it from the terminal. The code also escapes shell metacharacters in the process arguments to ensure safe quoting. After spawning, the parent process exits via a `stop()` call, leaving the daemon running independently.

AI-generated description

Similar vizzes