24

There are a bunch of managed cloud based hosting services for nodejs out there which seem relatively new and some still in Beta.

Yet another path to host a nodejs app is setting up a stack on a VPS like Linode.

I'm wondering what's the basic difference here between these two kinds of deployment. Which factors should one consider in choosing one over another?

Which one is more suitable for production considering how young these services are.

To be clear I'm not asking on choosing a provider but to decide whether to host on a managed nodejs specific hosting or on an old fashioned self setup VPS.

Yousef Salimpour
  • 694
  • 1
  • 7
  • 15
  • 1
    As some have notes, even if you go with a hoster, it's worth going through once to understand what's going on. Hopefully my links help ... – bryanmac Sep 30 '12 at 00:55
  • Thanks man, I believe I will go with Linode VPS for now so your links would be very helpful, although I was hoping to find some less obvious cons and pros specially on hosted solutions which seem quite blackbox to me now. – Yousef Salimpour Sep 30 '12 at 05:09
  • OK - makes sense. Added a bit more on pros/cons. I'll follow up if I think of more ... – bryanmac Sep 30 '12 at 12:42
  • I've never used the cloud hosting, and I've always used VPS for Node. It's actually been really easy to manage Node on a linux box. However, have you considered alternatives to Linode? I've always found them to be comparatively expensive. [Digital Ocean](https://www.digitalocean.com/?refcode=6f680d1e7f05) is fairly new and has great prices with quality service. – Sam Oct 12 '13 at 20:04
  • I'm finding these easy one touch cloud providers like Nodejitsu and Heroku having a dark side when I use them in production. The memory is really small per "VM", like 256MB small. Its like they design their systems to HAVE to have load balancing. Have only one node and its sorry slow and sometimes lags to wake up. Linode and Digital Ocean are pretty zippity quick and there is Amazon too but these require you to man up. – King Friday Jan 08 '14 at 07:33

3 Answers3

34

Using one of the services is for the most part hands off - you write your code and let them worry about managing the box, keep your process up, creating the publishing channel, patching the OS, etc...

In contrast having your own VM gives you more control but with more up front and ongoing time investment.

Another consideration is some hosters and cloud providers offer proprietary or distinct variations on technologies. They have reasons for them and they offer value but it does mean that if you want to switch cloud providers, it might mean you have to rewrite code, deployment scripts etc... On the other hand using VMs with standard OS as the baseline is pretty generic. If you automate/script/document the configuration of your VMs and your code stays generic, then your options stay open. If you do take a dependency on a proprietary cloud technology then it would be good to abstract it away behind an interface so it's a decoupled component and not sprinkled throughout your code.

I've done both. I did the VM path recently mostly because I wanted the learning experience. I had to:

  • get the VM from the cloud provider
  • I had to update and patch the OS
  • I had to install and configure git as a publishing channel
  • I had to write some scripts and use things like forever to keep it running
  • I had to configure the reverse http-proxy to get it to run multiple sites.
  • I had to configure DNS with the cloud provider, open ports for git etc...

The list goes on. In the end, it cost me more up front time not coding but I learned about a lot more things. If those are important to you, then give it a shot. If you want to focus on writing your code, then a node hosting provider may be for you.

At the end of it, I had also had more options - I wanted to add a second site. I added an entry to my reverse proxy, append my script to start up another app with forever, voila, another site. More control. After that, I wanted to try out MongoDB - simple - installed it.

Cost wise they're about the same but if you start hosting multiple sites with many other packages like databases etc..., then the VM can start getting cheaper.

Nodejitsu open sourced their tools which also makes it easier if you do your own.

If you do it yourself, here's some links that may help you:

Keeping the server up:

https://github.com/nodejitsu/forever/

http://blog.nodejitsu.com/keep-a-nodejs-server-up-with-forever

https://github.com/bryanmacfarlane/svchost

Upstart and Monit generic auto start and restart through monitoring

http://howtonode.org/deploying-node-upstart-monit

Cluster Node Runs one process per core

http://nodejs.org/docs/latest/api/cluster.html

Reverse Proxy

https://github.com/nodejitsu/node-http-proxy

https://github.com/nodejitsu/node-http-proxy/issues/232

http://blog.nodejitsu.com/http-proxy-middlewares

https://github.com/nodejitsu/node-http-proxy/issues/168#issuecomment-3289492

http://blog.argteam.com/coding/hardening-node-js-for-production-part-2-using-nginx-to-avoid-node-js-load/

Script the install

https://github.com/bryanmacfarlane/svcinstall

Exit Shell Script Based on Process Exit Code

Publish Site

Using git to publish to a website

famzah
  • 1,462
  • 18
  • 21
bryanmac
  • 38,941
  • 11
  • 91
  • 99
14

IMHO the biggest drawback of setting up your own stack is that you need to manage things like making Node.js run forever, start it as a daemon, bring it behind a reverse-proxy such as Nginx, and so on ... the great thing about Node.js - making firing up a web server a one-liner - is one of its biggest drawbacks when it comes to production-ready systems.

Plus, you've got all the issues of managing and updating and securing your server yourself.

This is so much easier with the hosters: Usually it's a git push and that's it. Scaling? Easy. Replication? Easy. ...? Easy. All within a few clicks.

The drawback with the hosters is that you can not adjust the environment. Okay, you can probably choose which version of Node.js and / or npm to run, but that's it. You have no control over what 3rd party software is installed. You've got no control over the OS. You've got no control over where the servers are located. And so on ...

Of course, some hosters allow you access to some of these things, but there is rarely a hoster that supports all.

So, basically the question regarding Node.js is the same as with each other technology: It's a pro vs con of individualism, pricing, scalabilty, reliability, knowledge, ...

I personally chose to go with a hoster: The time and effort I save easily outperform the disadvantages. Mind you: For me, personally.

This question needs to be answered individually.

Golo Roden
  • 140,679
  • 96
  • 298
  • 425
2

Using Docker is another way to simplify the setup on single Linux VPS. With Docker both development and production setups are faster, more robust, and more secure.

The setup is faster and more robust because you will be deploying ready Node.js image at once, without running any installation scripts. And it would be more secure because internal dependencies, such as database, can be hidden from outside world completely and accessible only from Docker internal network. On top of it, Docker significantly simplifies the upgrade process for underlying OS and Node.js runtime.

There are two ways to setup Node.js Docker environment. The first one – follow the instruction published here how to dockerize your application and deploy it with Docker, alongside with databases when needed. The guide gives the instructions for the development setup, the production setup will be similar.

Another way would be deploying official Node.js docker image and mounting application code as a volume or a folder to Node.js image. That would allow to update Node.js image going forward without re-building and re-deploying the application. Such approach solves long-standing problem with security patching of Docker images.

To help out with the setup of Docker on single machine - you can use Abberit Admin Panel. It will set up Node.js environment for you with a click of a button, including databases if you need them. The tool is free, and you can turn it off after you have completed initial setup. On the other hand, if later you decide to reduce maintenance tax of the production - you can migrate into managed service without any changes in the app.

Disclaimer: I am one of the founders of Abberit.