hosting nodeJS/mongoose web application on amazon EC2

i would like to host a nodeJS/mongoose/mongodb application in a cloud, and since EC2 has a MicroInstance that's free for 1 year, my question is: Are there any step-by-step tutorials how can I get up and running nodejs/mongoose application in Amazon EC2?

I used a couple of guides that really helped me out on putting a Node.js application on Amazon EC2.

The first one guides you through the creation of the instance and the installation of Node.js on that instance

How to setup Node.js on Amazon EC2 - Complete Guide

And then there's another one which could also be helpful to you, it has some more details about how making the Node.js app available on port 80 by tweaking iptables to forward it to port 8080

How I got Node.js running on Amazon EC2

For MongoDB, there's an official guide to se it up on Amazon EC2 on the official website

MongoDB on Amazon EC2

If you're just prototyping an application you may also consider using the free tier (500 MB) on MongoLab for creating your MongoDB instance without any effort, that will also save some resources on your EC2 micro instance running the Node.js application.

I recommend using Amazon's AMI

creating an upstart script for your js app

the following file can go in /etc/init

nodeapp.conf

description "node app"

start on runlevel [23]
stop on runlevel [016]

console owner

exec /bin/bash -l -c 'cd /path/to/app; /usr/bin/node server.js -p 9001'

respawn

from here you want to use nginx or apache to proxy to your node app

nginx can be installed via yum install nginx

for nginx the following block would work in your http {} config block

upstream app_cluster_1 {
server 127.0.0.1:9001;
}
server {
listen 80;
server_name domain.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://app_cluster_1/;
proxy_redirect off;
}
}

you can then start your app and nginx

start nodeapp

and

service nginx start/restart

if you are hosting mongo-db locally make sure to start it as well. I believe it ships with an init.d script

service mongod start

to auto run nginx and mongo

chkconfig nginx on

chkconfig mongod on

if mongo is not available as a package follow the steps on

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-redhat-centos-or-fedora-linux/