简体   繁体   中英

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?

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..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM