Starting HAP-NodeJS Automatically at Boot on Raspberry Pi

To automatically run the BridgedCore.ts or Core.ts service when your Raspberry Pi starts up, proceed as follows:

sudo nano /start

and enter the following (choose either Core.ts or BridgedCore.ts):

cd /home/pi/HAP-NodeJS
ts-node --files src/BridgedCore.ts

Now save the file by pressing CTRL+X and confirm with the ENTER key.
Change the permissions of the script you just created with the following command:

sudo chmod +x /start

Next, edit the rc.local file

sudo nano /etc/rc.local

and add the following line before exit 0

sudo sh /start

the result will look like the example below

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
sudo sh /start
exit 0

Save the file by pressing CTRL+X and confirm with the ENTER key.

Enjoy!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top