Friday, August 19, 2011

Creating a Node ExpressJS project on github: MadisonHQ

In this introduction to node, I will be using ExpressJS.  If you have not already done so, install NPM and then as root, "npm install express".

On my dev platform, I create a new Express Project:

express -s madisonHQ

This command creates a new folder "madisonHQ" and adds a skel app.js.  Head to git and create a new repository.

Now, lets get this setup on Git.
cd madisonHQ
git remote add madisonHQ
git init
git add .
git commit -m 'first commit'
git push -u madisonHQ master

As you can see here,, my new project is synced and repo'ed.

Depending on your environment, you might need to get the express library added to the project.  This is easy.  Inside the madisonHQ directory:
npm install express

Wednesday, August 17, 2011

MongoDB relational query and data customization

Lets talk about roles.  Roles, for my implementation, represents an application container.  An account may be granted a permission to this role, and run its applications.

For my relationalness, I always create a role permission collection, p_roles, that links references to the account identifier as well as the role identifier.

This is where my last example came in.  This time, however, I want to populate a grid of accounts that do not exist in a role, so that the interface user may add them to it.  This required two things:
  • an array of account ids we want to exclude
  • a 'not in' query
This example might be more complex than it needs to be, but the complexity lies in keeping each forEach loop asynchronous. I needed to customize the returned data because the accounts collection contains password hashes and other information not necessary for the front end user.

Sunday, August 14, 2011

MongoDB and Relational queries? Yes it can!

Hello internet, today I would like to give a little information on a misconception with MongoDB.  NoSQL explicitly denounces relational queries as a thing of the past, however it is necessary to normalize  your data and keep it efficient and avoid having duplicate information.

For my discussion today, I will refer to vendors permissions, which was for a sample purchasing app I demoed inside portalstack.

To do a relational look up, you need to do a bit of async programming.  For me, I used the async library provided by the nodejs community.

First, I query my permissions collection, p_vendors, for an account_id and the vendor_id, both are ObjectID references.

Next, I use async to foreach the returned permission set.  When the async call is complete, it returns the prepared data to ExpressJS and its sent off to the client.

Thursday, August 11, 2011

Installing NodeJS and NPM

I will be installing NodeJS 4.1.0 on ubuntu 11.04.


  • sudo apt-get install open-ssl libssl-dev

Get the archive

Unpack the archive
tar zxvf node-v0.4.10.tar.gz ; cd node-v0.4.10/

Configure the compiler and install
sudo ./configure && sudo make && sudo make install

Finally, install NPM.  This you must do as root, otherwise it gets messy
sudo su -
curl | sh