Josh McArthur

Treatme Lite: Part One - the Backend

08 Feb 2012

The Backend

This article first is in a series of three blog posts documenting how I created TreatMe Lite, an HTMl5 web app using Zepto.js, Coffeescript, and a range of other frameworks and tools, all backed by an Express JS web service. See my previous post for more information about the application.

Last post (the intro), I left off explaining why I set out the build the application, and the technologies I had selected to build each part. This post is going to detail the steps I took to create the web service using NodeJS and Express.

First of all, I needed a way to serve the deal JSON. In actuality, this is something that I could have done just as easily directly from the front-end Javascript, however, I’d started off with a NodeJS application, and it seemed just as sensible to request the JSON from TreatMe using Node’s support for HTTP requests.

To kick off the node app, I cloned a starter application from Github:

git clone git:// treatmelite

This application gives us an easy base with support for Coffeescript, Jade templating and a bunch of other CSS stuff, like the Skeleton grid (which I’m a big fan of).

To satisfy the requirements for the front-end, my NodeJS application needed to perform two tasks:

/deals/:latitude/:longitude: Retrieve a list of nearby deals from TreatMe

The code:


/geocode: Geocode an address, and pass back the information we need to display to the user

The Code:


A note on Geocoding: We use Google’s Geocoding service to retrieve the information we need from either the name of a location, or the latitude and longitude (either way, it fills in the information we need). Once again, this is something we ideally would do from the front-end, however, I ran into some cross domain issues, and so simplified matters by performing the request on the server