'Node app running on cPanel hosting shuts down after 30 minutes idle

I have a REST api node app. Once its running on localhost, it runs until I stop the dev debugging, no errors. I moved it over to my cPanel hosting, installed a node app. It starts up the same as localhost. But after 30 minutes being idle, it shuts down. The next request after this, restarts the app. There are no crash or errors in the log, just the restarting messages.

I know this is default behaviour for free hosting, like Heroku but I'm paying for this hosting package.

Does anyone know... Is this default behaviour for cPanel hosted node apps, or is my app causing this (using too much memory or cpu for example? Is there any settings that can be edited to change this?



Solution 1:[1]

According to the docs, cPanel uses something called Phusion Passenger to run Node.js. In turn, Passenger docs show a default "idle time" of 5 minutes and a default of passenger_min_instances = 1. No idea if cPanel changes the defaults, or if the hosting provider did. I would recommend contacting the hosting provider about the issue in any case, and asking about these options specifically - they may be able to help or tune the service for you.

Solution 2:[2]

The startup time for a node app depends on what it's doing. A rest-api could be in the milliseconds, whereas a small Ai app loading a corpus or training a dataset (which mine was) could end up being 30 seconds plus. However the quantity of users did not warrant a dedicated server, so the work-around was to call the endpoint using a CRON, keeping the app alive.

Not perfect, but this type of thing may be useful if you are using aws lambda, which calls a 3rd party service, and which charges based on time taken. Every millisecond counts.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Robert Kawecki
Solution 2 macasas