Hosting Node.js and MongoDB
After digging into web development with Node.js the last couple of months I had to choose where to host this blog, which I had decided to rewrite and run with Node as a result of my research.
To be honest, I’ve been surprised there is no real ecosystem of (shared) hosting providers offering Node.js and MongoDB (which often is the obvious choice when developing a node application) on the cheap.
So it seemed to be a Do-it-yourself-world. Challenge accepted! :-)
My personal requirements were:
- Run Node.js and MongoDB (or any other database) side-by-side. I don’t want to host my data in a datacenter hundreds or thousands of kilometers away.
- Easy possibilities to back up files.
- Reasonable cost effectiveness with predictable pricing.
Option 1: Run your own physical machine
I am running Windows servers for my clients and some personal projects for more than a decade, and for all of these more or less small to medium-sized projects it has been sufficient to run IIS and SQL Server as well as other stuff together on single machines.
I always trusted Hetzner as their dedicated servers are not only cheap but also powerful and reliable. And even if some hardware fails, their support is fast and competent – even on Sunday mornings ;-).
If you want a powerful physical machine on the cheap - go for Hetzner and set up your server according to your needs.
I’ve published the “Node.js Web Server Guide” which describes how to set up an Ubuntu server to run multiple Node.js applications side-by-side.
Hetzner also offers free 100 GB backup space for each dedicated server. The guide contains a description how to use it, too.
Option 2: Run each site on its own Virtual Machine
The cheapest dedicated server offered by Hetzner is currently the EX40, which costs exactly 41.18 EUR a month (plus taxes depending on your country and if you’re a private person or a business). And even if you get 32 GB RAM, 2 TB HDD and a quad-core CPU for that money, it may be a little bit over-sized for a single website (like my blog).
If you are running more than one site, there are other disadvantages, too:
- Misconfiguring a single part of the system affects every application depending on it (think of a corrupt global npm package or a failed Node.js upgrade …).
- Security vulnerabilities on a single site may be abused for other sites, too.
- Attacks or even traffic peaks of a single site affects the whole server.
- If the hardware crashes, all sites are down all at once, so you have to deal on multiple fronts.
Obviously there are so many disadvantages, it seems worthwhile to look for alternatives.
I have been working with both AWS and Azure, and all of them, including Google’s offer, are viable options. But for my taste all of them are a bit too much for my needs, again. I don’t need endless scalability, at least not for now. But I do need a predictable pricing model, which none of these candidates offers.
While learning how to set up all that Linux stuff that was new to me, I often stumbled over articles published on DigitalOcean. And their tactic of great content marketing worked – I got curious about their offerings and decided to give it a try.
Today this blog runs on a virtual server with 1 GB RAM, 30 GB SSD Disk and 2 TB transfer volume – more than enough even for little peaks. The server itself was up and running after less than a minute, including a preinstalled version of Node.js, thanks to their great and simple administration tool.
I bought backups on top for 20% of the server’s price a month, so it costs about $12. But as they “only” back up the complete machine every couple of days and I want to be able to backup relevant files (web, database, nginx configuration) more often and regularly, I also rented an additional small virtual server at Hetzner.
This one is now running with one single role: storing backups from all of my servers on DigitalOcean. I think it’s really unlikely to lose data there, but I am sleeping much better by knowing everything important is backed up each day to a server which is running in a completely different and independent data center.
I could also have been setting up another DigitalOcean droplet in another data center, but it would still be DigitalOcean. So even if hell freezes I will be able to access my data on the Hetzner server.
I’ve written another guide which provides detailed explanation about how to run a node app on a single server, which requires less security considerations than a shared environment: “Setting up Ubuntu Server for running a single Website with Node.js and MongoDB”.
After running all of my (ASP.NET) stuff on only a few physical servers over the years I am now contented with the second option. I think I will go for it for everything that doesn’t need the full scalability possibilities of the “Big 3 cloud providers” for the next time.
Do you have a software project you’d like to discuss?