Sunday, November 27, 2011

Keeping the node going

So just running node as a background process isn't very stable.  A better way to run it is under a separate process that restart it if it stops for some reason.  I guess there are some general purpose solutions for this sort of thing like Monit, but there's also a custom node package for this called Forever.

Monday, November 21, 2011

Fun with Unix

So that's pretty cool.  Unix makes it easy to run a process in the background.  Just add an ampersand at the end of the command.  eg run
node ~/example.js &
instead of just
node ~/example.js
and I'm good to go.  Useful cheatsheet I found here:
http://kb.iu.edu/data/afnz.html

I've also got Redis installed and was able to run that as a background task as well.  However, even in the background it was spamming the console with status messages.  What I needed to do was modify the conf file and set
daemonize yes

And now I'm just about ready to start developing.  For my IDE, I'm going to try out Aptana Studio.  It's a modified version of Eclipse geared towards web development.  In terms of my setup, I've been reading about backbone.js, which seems like a cool mvc framework for javascript.  I've really come to like the MVC stucture since working with microsoft's mvc.net.  I'll also be using require.js and maybe underscore.js.  Not sure about that last one yet.  I still need to read more about it's uses. 

Success!

http://Phintos.com/
I was almost there.  I just needed to, you know, start the webserver.  So after starting nginx and running my example node file, I have a working website.  Running node seems to block the terminal though.  There must be a command to run it in the background...

Step 3+4: Fun with Linux

Blarg.  Setting up an ec2 instance with node has been a pain.  Not quite done yet, but I'll share my AMI when I am.  I'm not going to go into all the details here, but let me share some mistakes I made.

Mistake 1: Amazon linux AMI.
When setting up a virtual server in ec2 you choose a base configuration to start with.  Looking at the options, Amazon has a custom AMI (amazon machine instance) that sounded lean and mean, so I chose that.  After configuring my keys and finally ssh-ing into the box though, I realized it's based on a different linux flavor than most online node.js tutorials are geared towards (it's CentOs instead of ubuntu).  I didn't want to abandon my new instance though, so I forged ahead.  Luckily I found this useful blog post:
http://wavded.tumblr.com/post/475957278/hosting-nodejs-apps-on-centos-5
but it's still been painful.  Now I've got node set up and all it's dependencies, but I'm still struggling with nginx.
Also, another thing that took me a while to find: the right way to ssh from a mac to an amazon linux ami:
ssh -2 -i <yourKey>.pem ec2-user@ec2-XX-XX-X-XXX.compute-1.amazonaws.com
Also, make sure your key permissions are restrictive enough:
sudo chmod 600 <yourKey>.pem

Sunday, November 20, 2011

Step 2: Set up Git Repo

So I decided on a cool name: "Phintos." Kind of a combination of Fin and Photos, since this is going to be a site for organizing photos of dolphins.  More about this later.  So here's the Github repo I just set up:
https://github.com/whalefood/Phintos
 To set this up, I followed a list steps blindly.  So now I'm going to go back and figure out what exactly I did:
After creating naming the repo on git and creating a local folder, I ran
>git init
It looks like this sets up the initial local files git needs to be able to work with a directory.

Next I ran
>touch README
This is a unix command to create an empty readme file.  It looks like it can also be used to update permissions and modified date of a file.

Then I used >git add and >git commit to add this file to the repo, which I assume work similar to subversion.  The actual commit command was
>git commit -m 'first commit'
According to http://gitref.org/basic/  the -m option is used to add the commit message in the same line.  This looks like a very useful site.

Step 1: Set up blog

Welcome visitor! (Aka me).  This marks the completion of the first step of my project: setting up a blog to document my progress.  With this project I aim to learn some new technologies and maybe produce something useful in the end.  I plan to use an learn Html5, node.js, Redis, Amazon S3 and EC2.  I'm going to make all my code freely available on Github.  I'll go into more detail about what the actual project is later on.  I'm developing on a Macbook Pro so any software I write about will be OSX compatible.  Next step: set up Github accout.