Sunday, March 16, 2014

OOP in Node.js / JavaScript

So ECMA standards have support for two type of OO programming structures.

1) Classical: The regular class based structures.
2) Prototypical: Where u can use any function from anywhere, as they are not class based.

I have been reading these awesome content:

1) http://book.mixu.net/node/ch6.html
2) http://dmitrysoshnikov.com/ecmascript/chapter-7-1-oop-general-theory/
3) http://howtonode.org/prototypical-inheritance
4) http://javascriptweblog.wordpress.com/2011/05/31/a-fresh-look-at-javascript-mixins/


These people are awesome.

Thanks..!

Tuesday, March 11, 2014

How to make the EC2 instance of node.js or any application point to my registered domain name??

Considering an example from GoDaddy.com

1) Goto manage your DNS.
2) Goto A host settings.
3) Change the IP to your EC2 machines IP.
4) Changes can be instant or they can take upto 48 hours.
5) Enjoy!



Deploying Node.js Express application on AWS

AWS provides a free account for experimenting with their cloud.

Joyent is a competitor in terms of deploying Node.js applications.

Node.js + MongoDB = Awesome at Joyent (+ mongoLab).

Today I deployed my website on aws ec2.

Here are the steps:

1) Create an account on amazon.
2) Goto dashboard.
3) Create a new instance of amazon ec2. (its very intuitive and easy to use, lots of resources on google.)

4) Rerouting inbound port 80 to whichever port you are using in your application.
steps:
a) sudo bash
b) iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
c) Save to a file:
    iptables-save > /etc/iptables-up.rules
d) save it to startup configuration file:
echo "post-up /sbin/iptables-restore < /etc/iptables-up.rules" >> /etc/network/interfaces
e) Done.

5)Install node.js from there github repository.
take the stable release branch: https://github.com/joyent/node/tree/v0.10.26-release

6) install npm, express, mongoDB or any other modules you want to.

7) clone your application

8) Go back to aws. Goto security groups.
a) Add All ICMP port with source whatever you like or keep as default.
b) Open TCP port 3000.

9) Goto amazon ec2 instance. Spin your application.
10) Enter your public DNS with your port (here it is 3000).
11) Enjoy!