If you have a Node.js app running on an OS X server, you probably:
While pm2 has the ability to generate startup scripts for use with Ubunutu, Centos, and systemd, it does not work with OS X. The best approach is to use launchd, an OS X-specific daemon manager that replaces cron
. It uses XML-based files for configuration. This guide will walk you through the process. Note: “xyz” is used as a placeholder for the application name throughout this guide.
sudo vi /Library/LaunchDaemons/org.node.xyz.plist
org.node.xyz.plist
, altering it with your configuration, and save (:wq
) and exitsudo chown root:wheel /Library/LaunchDaemons/org.node.xyz.plist
sudo chmod 644 /Library/LaunchDaemons/org.node.xyz.plist
echo $PATH
sudo vi /etc/launchd.conf
launchd.conf
, but use whatever $PATH
you just echoed, then save and exitsudo shutdown -r now
- this will reboot the system. If you skip this step, the changes to launchd.conf
will not take effect.sudo launchctl load /Library/LaunchDaemons/org.node.xyz.plist
sudo launchctl list | grep xyz
. Three columns will be returned - PID
, status
, and label
. If there is no value for PID
, but there is a value for status
, something went wrong.pm2 list
and see your Node app running. If you get an error, you might need to sudo chmod 777 /Users/<<me>>/.pm2/pm2.log
.