Last Updated: February 25, 2016
·
637
· geta6

daemonize nodejs

daemonize your application :P

unless process.env.__daemon
  args = [].concat process.argv
  args.shift()
  args.shift()
  process.env.__daemon = yes
  child = spawn process.mainModule.filename, args,
    stdio: 'ignore'
    env: process.env
    cwd: process.cwd()
    detached: yes
  child.unref()
  process.exit 0
fs.writeFileSync 'app.pid', process.pid