Basic Node.js and Backbone.js application III. Cloud Foundry, Heroku and AWS

16 Abr


In the previous post, Basic Node.js and Backbone.js application I and Basic Node.js and Backbone.js application II, about how to build an easy Node.js and Backbone.js application we discuss about which technologies we were going to use and after that we built a simple web application along with some REST API such as Twitter and the Yahoo Geoplanet API.

In this third post we speak about how to deploy our recent Backbone.js application to the cloud. I decided to use third of the most used PaaS (Platform as a Service) nowadays: Heroku, Cloud Foundry and AWS. Yes, I know that AWSis considered for many people an IaaS (Infrastructure as a Service).

I was also interested in giving a try to nodejitsu a specific platform to Node.js environment that belongs to Joyent. Unfortunately, they are currently in Beta   and it seems imposible to get a invitation in the last couple of weeks. I’d like to upload the application to Windows Azure that is growing fast lately. I might update this post as long as I deploy the application to other PaaS. Meanwhile, we’re going to deploy to the three platform already commented.

Deploy to Heroku

Previously to deploy our application to Heroku we need an account. Fortunately, you can sign up for a free account. To deploy this basic Node.js you will need no more than this simple account. If you need some more features you always can upgrade your account to get the best of Heroku.

Once you get your free account, you can deploy your Node.js following the instruction within this link. Heroku brings us some simple commands from our console, to directly upload our application. To do that you need to donwload the Heroku Toolbelt. After that log in your account.

heroku login

You’ll be asked for your account email and password. You need to create a couple of files in order to upload your project to Heroku:

  • package.json. In this file you define your project’s dependencies. You’ll define your dependencies in a similar way you’d do with Maven.
  • Procfile. You will assign the init file in your application. In our case our init javascript file is called app.js. So we are going to define our Procfile in the following manner.
              web: node app.js

Before you deploy your application to the cloud you must commit your last changes into your local repository. You need to create a Heroku instance where you’ll deploy your application. After that you just push your code to Heroku. Finally run your application and open it to check if everything was right. These last steps are as follows:

git commit -m "init"
heroku create --stack cedar
git push heroku master
heroku ps:scale web=1
heroku ps
heroku logs
heroku open

Deploy to Cloud Foundry

Cloud Foundry is a PaaS by VMware. I’ve already uploaded some application to this PaaS. You can read more about it in this previous post Deploying a Grails application to Cloud Foundry. Cloud Foundry is an Open Source project, which it’s something great. You can  download it and see how it works. You can modify it as you need it as well. You also have Micro Cloud Foundry, this is no more than a version of Cloud Foundry that runs in your local machine.

As Heroku does, you need to sign up for a (free) account in its home page. Similar to Heroku you need to install a command-line utility called vmc. You have one more possibility, if you use Eclipse or STS as your IDE, you can install a plug-in for Cloud Foundry. If you give a try to this plug-in you will notice that works quite nice.

Install the command line and open your console. You need to log in Cloud Foundry. To create a new Cloud Foundry application you have to use the push command,  after which you’ll be asked to fill some information about the newly created application. If you want to modify your application you’ll use the update command.

vmc login
vmc push || vmc update app_name

One thing you need to be aware of is that you have to change the port where your server will listen. This port is defined by the VMC_APP_PORT property.

var port = (process.env.VMC_APP_PORT || process.env.PORT || 3000);

Deploy to AWS

AWS delivers a set of services that together form a reliable, scalable, and inexpensive computing platform in the cloud”. It gives us a great set of solutions to work in the cloud, such as Databases, content delivery or networking among other. You can find an explanation of them in this page.

In our case I’ve used EC2 (Elastic Cloud) to deploy our application. I truly recommend to follow the next guide given us by Ben Nadel. By every meaning you don’t to do nothing more that what is explained in this guide. Kudos to Ben Nadel!

Installing a Node.js application in EC2 is not as easy as with Heroku or Cloud Foundry, but we can take a great way of configuring our system instead.

My Two cents

If I have to choose one of the 3 previous PaaS (IaaS in the case of AWS)) to deploy my application I’ll probably use Heroku. For what reasons I would do that?. Well, it’s really simple to configure and deploy your application to the cloud. You only need to add to external files to your project defining your dependencies and your main javascript file. Cloud Foundry is even simpler but I don’t like that you need to change your code to indicate a specific port.

I’d also say that AWS is in another league. It gives you more possibilites in your configuration and it might be a good option for your production environment but if you want to start with deploying your application to the cloud Heroku or Cloud Foundry may be more suitable. Besides that you can find some services like MongoDB or RabbitMQ that you don’t find so easily in AWS.

The three of them have a free (or almost free) account, so it’s really worthy to give a try to all of them. You can find a brief HOW-TO in the README file within the project.


You could be interested in reading the other posts:

3 comentarios

Publicado por en 16 abril, 2012 en Cloud Computing, web


Etiquetas: , , , , , , , , ,

3 Respuestas a “Basic Node.js and Backbone.js application III. Cloud Foundry, Heroku and AWS


Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s

A %d blogueros les gusta esto: