forever

Start a Node.js app with Forever and Ansible

Forever is a really simple and flexible tool to daemonize Node.js apps. Instead of running them with nohup node /path/to/app.js &, run them with forever (so you can forever start [app] and forever stop [app], among other things). Server Check.in uses Ansible to deploy our Node.js apps, and there's currently no Ansible module to control forever like you control service, but you can still use the following plays to install forever and run your app:

<br />
    - name: "Install forever (to run Node.js app)."<br />
      npm: name=forever global=yes state=present

- name: "Check list of Node.js apps running."
command: forever list
register: forever_list
changed_when: false

- name: "Start example Node.js app."
command: forever start /path/to/app.js
when: "forever_list.stdout.find('/path/to/app.js') == -1"