How To Get NodeJS Service Continuous Uptime - One of the problems that NodeJS developers often get is that the service is not uptime continuously. Then how to keep NodeJS service uptime 24 hours? In this guide, we will explain how to make NodeJS services uptime continuously.
Remember, the NodeJS feature is only available on Super Hosting Packages and above !
How To Get NodeJS Service Continuous Uptime
In order for the script that has been created berjalan secara terus menerus, you can use the one Forever.jsthat can be downloaded for free at https://github.com/foreverjs/forever .
Forever.js ini berfungsi untuk menjaga agar proses Node.js tetap berjalan. If the service shuts down suddenly, the Node.js service will automatically restart. As for step by step using forever.js, namely,
1. Perform SSH access
Please akses server/ hosting yang anda miliki melalui SSH. For SSH remote processing, you can use the Linux terminal or Putty Software on Windows. For those who don't know, please follow the SSH Access Method on cPanel Hosting
2. Go to the Node.js Folder
After that, the masuk ke direktori/ folder tempat dimana aplikasi/ script Node.js berada. You need to do a few terminal commands to change directories. Please type cd (space) in the Node.js script folder . For example, in this tutorial the Node.js script is located in the node folder. Then the terminal can be written cd node /.
3. Download Forever.js
If it is already in the Node.js script directory / folder, the next thing is melakukan download Forever.js. As for the method, please type
npm install forever
Wait for the installation process to succeed.
4. Run Forever.js
Now is the time to start the Forever.js service. Untuk menjalankan Forever.jsplease write the following command. Keep in mind that Forever.js can only run when you are in the Node.js script (application) folder / directory!
./node_modules/forever/bin/forever start hello.js
In this example, hello.js is a Node.js script (application). So, in order for the script to continue running, you have to run the Forever.js service in this way.
To find out the error_log, please add a command
./node_modules/forever/bin/forever -o out.log -e err.log hello.js
Running NodeJS with PM2
Apart from using Foreverjs, you can also use PM2 so that the NodeJS service can continue. Please read How to Set NodeJS Using PM2
One way to make NodeJS service uptime continuously is using forever.js. You can download forever.js for free. Once downloaded, make sure the forever.js service can be run properly. Want to try a NodeJS based Ghost application? Please follow How to Install Ghost on Hosting . Do you want to upgrade your hosting? Please check KincaiHosting Best Hosting .