« Back
in node.js linux read.

Automatically start a node application on system startup.

Important: This is no longer recommended. Please use a process manager like PM2.

It's just a simple cron job, called on every reboot. There may be many other better methods, But I just wanna share what i did. It's actually a cron, to execute on every reboot. So, We need to write the commands to start the server in an .sh file, and call it via cron. The same method can be used for any other purpose, other than starting a node.js application.

Let's assume, we have a projects in the home directory, project1 & project2. And am writing a simple sh file in the home directory, startup.sh. And it's like,

nohup node /home/project1/app.js &  
nohup node /home/project2/app.js &  

In the above scripts, I've used nohup(no hangup) to make the application to work til the machine is On. Now, we have the script file, and we need to add this in the crontab.

Just open crontab inm terminal,

crontab -e

Add our command, to execute sh file.

@reboot /bin/sh /home/startup.sh 

And, we are done! Reboot your system, let it work ;)