Start Node-RED on OS X login

Start Node-RED on OS X login
Node-RED flow for controlling a Blink(1) USB indicator light

Node-RED is a truly awesome framework for visually building data flows. There is a lot of focus on wiring together hardware devices and Internet of Things, but there are also plenty of modules for connecting to email, social media, various online services etc.

After using it during some months I can confirm that stability is absolutely fine, don’t think I have had a single issue with the setup due to Node-RED itself.

Version 0.10.1 came out a week or so ago (early Feb 2015) and brought things like better partitioning of flows in the form of subflows, improved Raspberry Pi support, binary MQTT payloads to name just a few of the improvements.

I am running Node-RED on an always-on Mac, running latest OS X. This machine is very stable but for various reasons I do need to restart it every now and then. It would then be very nice to have Node-RED start automatically at boot. That’s somewhat complex to do, but having an app starting at login is trivial – let’s do that instead. I am always logged into this computer anyway, so it won’t be a problem.

In my case I am using forever to ensure that Node-RED always is running and that it is restarted if it for some reason fails. It adds a nice safety net around Node-RED. In other words – it is forever that should be started at boot, forever will then start Node-RED for us.

Thus, as a first step ensure that forever is installed. Instructions are found at the link above.

Then start Automator and create a new application. Add a new “Run Shell Script” action to the Automator app, and enter the commands to the right. Customise as needed for the paths on your own system:

OSX Automator used to create a shell script, packaged as an executable application
  1. The “usr/local/bin” should point to the path where the forever command lives. Run “which forever” from a OS X command line (using iTerm2, maybe? Outstanding terminal program!) to find the path on your system
  2. Change “/Users/goran/code/node-red” to match the path of your node-red installation
Launch forever node.js app from Automator app

Save the Automator app in a suitable location, for example in an “Automator apps” directory under your home directory.

Configure what apps are started at login

Finally, create a new login item for your user. This is done from the “Users & Groups” section of the OS X “Systems Preferences” app. Click the plus sign to add a new entry, point it to the newly created Automator app, and make sure the new entry is enabled.

Done – forever will now start Node-RED automatically when I log into the computer.