After developing my first node.js app I decided to look where to host it. It had to be cheap and fast to deploy.
My first attempt was to deploy to heroku. It’s very very easy (if you’ve used git before… it could be the easiest thing you’ve ever done), but I think (and I tell that I only think because I didn’t finish deploying on it) is a little expensive. Every module you use have to be in its starter mode, or you have to pay for it.
So, after watching how many projects have successfully gone up with amazon web services, I decided to deploy on it. Maybe I’m wrong, but i think that for a small app, AWS could be cheaper than heroku (I’ll tell you after some months =) ).
Why am I writing this article? Maybe there’re some articles that refers to this… but I wanted to keep track of what I did in case I need it again.
First thing we have to do is to sign in AWS if you’ve not done before, and after that you must enter the AWS Management console and select EC2 (Virtuals servers in the cloud). You can click on the image to see it better.
After that you’ll be on the home page where you can do all the options available from EC2 like creating instances or key pairs
Now, we can launch our server instance to deploy our apps following the wizard. It’s very easy and on multiple AWS versions it’ll change, so I’m not uploading this images… but if you want to know I installed an Ubuntu 12.04 server.
After creating the server, you’ll have a key pair to connect via ssh (or however you want, but this is the way I’m doing here).
Once you have your keys, you can copy them into your .ssh folder: ~/.ssh, and give them the permissions to use it (i’m using a key pair called ubuntu.pem):
$ chmod 600 ubuntu.pem
To make the ssh connection you just have take the address to your server and connect typing your password. You can take the address from this page clicking on your instance (it’s the amazonaws’ string):
Now type the following, and you’ll be connected:
$ ssh -i .ssh/Ubuntu1204.pem firstname.lastname@example.org
After connecting to our AWS instance, we need to install git & node:
$ sudo apt-get update $ sudo apt-get install git-core curl build-essential $ sudo apt-get install openssl libssl-dev $ git clone https://github.com/joyent/node.git && cd node $ ./configure $ make $ sudo make install $ echo 'export NODE_PATH=/path_to/node' >> ~/.bashrc $ echo 'export PATH=$PATH:/path_to/node' >> ~/.bashrc $ source ~/.bashrc $ node -v
When all of this finish, we’ll get our node.js version and It’ll be installed (this will install last node version). To install another version, for example, 0.6.19, you need to checkout another branch before configuring:
$ git checkout v0.6.8
After this, you can run your own node js on amazon web services! but, for all node.js must be missing something: npm. This package manager makes all easier, and perhaps, you may have it on AWS too. So, to install it just do the following:
$ git clone http://github.com/isaacs/npm.git && cd npm/ $ make install
As always, you can install Express like this:
$ npm install -g expressHope this helped! In the next article I’ll show you how to use git to push your code to your AWS Server.