Search code examples
node.jsherokuserverhostingnode-postgres

How to prevent downtime on Node.js web server


I have a Node.js web application and a postgres database being hosted on a raspberry pi on my local network. They are being frequently accessed by other devices on the local network during the work day, and any system downtime results in the delay or failure of operations.

What are some possible solutions to this issue? Do I need to deploy the Node.js web application using something like Heroku or is there a way that I could add redundancy by hosting the Node.js web application on multiple different machines to allow the application to keep running in the event of a crash?


Solution

  • You can use some process manager for node.js like PM2. You can setup restart strategies for your nodejs server. When it crush PM2 will restart it. See this docs. Also it can running you nodejs app in cluster mode - you can have separate instances of you app and PM2 will distribute all request between them.
    Also if you nodejs process crash because some errors happen, try to process this errors in right way, without finish process. Add try catch when it necessary, handle async errors, etc..