Home > Enterprise >  Launch local node server at system boot
Launch local node server at system boot

Time:11-12

I'm working on a Raspberry Pi running nextjs (node server) connected with nginx. I tried using x-terminal-emulator ‘/usr/bin/bash -c /home/pi/Desktop/startup.sh’ but many of them didn’t recognize /usr/bin/bash as a directory and most of them didn’t budge to execute the script. In how many ways can I start my bash script? What is the most useful way possible?

These are the ways that I tried and the errors corresponding to them.

  • contrab -e: Didn’t budge to execute the command line
  • rc.local: DIdn’t budge to execute the command line
  • systemd: /usr/bin/bash file or directory doesn’t exist.

I’ve must of been using them incorrectly. If so what is the way to use them?

CodePudding user response:

This recipe allows you to launch node server at system boot. In this recipe it is assumed that you have a node server running on port 3000.

Steps

  1. Add node server to the rc.local file

sudo nano /etc/rc.local

Add the following line to the rc.local file

sudo node /home/pi/node_server.js

  1. Make rc.local executable

sudo chmod x /etc/rc.local

  1. Reboot the system

sudo reboot

  1. Verify that the server is running at boot

sudo netstat –lntp | grep 3000

This should output node server which is running on port 3000.

  1. Verify that the server is accessible from remote computer

curl -i http://<ip_address>:3000

  • Related