General production advice

From time to time, I see the question of production setups being asked in GitHub issues as well as in some of the hapi community chat rooms, so I thought I would provide some information here. While Eran published a GitHub gist detailing Walmart's setup (https://gist.github.com/hueniverse/7686452), they were using hapi mainly as a proxy, and I'm pretty sure most production environments won't be at Walmart's scale dealing with events such as Black Friday.

The production setup I see most often with Node, and one that I have used regularly in my own setups, is to have a dedicated web server such as Nginx or Apache to act as the public interface responding to requests on port 80 for HTTP and 443 for HTTPS. I then use these as a reverse proxy to my Node application running hapi. This is so that HTTPS can be handled by the web server terminated prior to reaching the Node hapi-based application, so the Node applications can focus purely on business logic. Often, I have multiple applications running on a single server, and by using something like Apache, I can use vhost-based proxying to different applications at the web server level.

For managing my node processes, I normally use the Node process monitor PM2 (https://github.com/Unitech/pm2), where any deployment tool will run a post-deployment hook for restarting all Node processes, with zero downtime via PM2 and Node's cluster module. It might be tempting to use the watch & restart functionality of PM2 here, but don't. That is for development environments. As soon as PM2 is notified of a file change, it will begin to restart the process; this may complete before all the files have been transferred to the production server, creating very unexpected results!

For monitoring and logging, I have used a combination of the module good and third-party services such as New Relic (http://newrelic.com/), which have both served well. My main advice here is that whatever you use as your monitoring service is fine, just make you sure you have a monitoring system; you'll figure out your needs pretty quickly. Until then, you're operating in the dark.

For databases, it depends on the application. In some cases, I have just used a database installed on the same server as the hapi application, while in others that required a higher level of security and robustness, I used a separate database server.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.226.121