I now have a working version of JetFuel Express live on Heroku at http://jfx.herokuapp.com. Please check it out!
At the moment, I have a basic link shortening service working. Here’s a glimpse of what it looks like:
And here are the technologies I’m using:
I’ve been working really hard at learning Backbone, a client-side MVC (actually MV*) library, over the past few weeks. I had started to look into Ember.js, and was having a hard time. My mentor, Mike Pack (who works at Mode Set), suggested looking into Backbone first, because: “you’re going to burn a lot of mental cycles trying to learn Ember and Rails at the same time”. This has turned out to be some really good advice. For me, Backbone fairly intuitive, yet still quite challenging to learn.
I did a few tutorials. I found this RailsCasts one to be the most approachable. This Nuttuts+ Premium Tutorial was interesting. It was written with Coffeescript and Handlebars. There were some others that were less remarkable, but they still helped me get familiar with the library.
I still felt like I needed to understand more, so I checked out the book Developing Backbone.js Applications by Addy Osmani, available free online. It covers many Backbone topics, and has quite a few tutorials. In the first one, it walks you through building a simple to-do app called TodoMVC in Backbone.
My favorite tutorial from the book was the Book Library tutorial. It really makes it clear how to use Backbone to talk to an API. It also teaches you build that API in Express.js. It was essentially the inspiration for my app.
Backbone can be really hard to debug. The value of the keyword ‘this’ can get kind of tricky, in particular. For example, in my UrlsView class, the value of ‘this’ shifts from the Backbone View object to the urlCollection, so I have to assign it to ‘that’ before passing it into the callback function. This was a subtle problem that was breaking my view, until Mike helped me fix it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Here’s a look at how I built the rest of my stack:
It’s summed up well on the Mongoose website. Mongoose is a “MongoDB object modeling tool designed to work in an asynchronous environment”. It’s like DataMapper or ActiveRecord in Ruby. It has some really powerful validations baked in:
1 2 3 4 5 6 7 8 9 10 11 12
This lovely framework is the foundation of my backend. It is architecturally based on Sinatra, and is very similar to work with. It was really easy to get a project up and running quickly in Express using Node Package Manager (see below). Since it’s built on Node, it is very fast. I used it to set up an API server to send and recieve JSON requests from my front end.
We used this testing framework quite a bit in class for Exercism exercises. It felt like a natural choice. Although I am usually more comfortable with ‘assert’ style test statements like you find in Minitest, I found Jasmine to be pretty intuitive. Here’s an example of one of my tests:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
A couple days into this project, I was tweeting about what I was up to, and an Express.js dev tweeted back at me, suggesting I check out his Express.js tutorials. He also recommended the Mocha testing framework. I haven’t had a chance to dig in yet, but it looks promising. The website says that you can use your favorite style of assertion (‘should’, ‘expect’, or ‘assert’) by loading different libraries - Chai, Should.js, Expect.js, or Better Assert.
I was looking around for some kind of acceptance test solution along the lines of Capybara. I couldn’t really find anything I liked, but I did stumble on this “headless browser” testing framework. Although it looks promising, I’ve had a lot of trouble making it work the way I want. I wouldn’t really recommend it, unless you have extra time to figure out how to make it do what you want.
After giving a lightning talk about Mustache a few weeks ago, I just had to try Handlebars for this project. It went pretty well, as long as I didn’t try to inject anything that was null into my templates. When I did that, it killed the server.
Bits and Pieces
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
Node Package Manager (NPM)
I really like how easy it is to install Node.js dependencies. I’ve been spoiled with Bundle, so it felt comfortable to be able to add things I needed with ease. You just declare your dependencies in a package.json file in your application root, then run ‘npm install’. The package file is in JSON, so it’s not as pretty as a Gemfile, but it will give you all the things you need. Here’s what mine looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Mongoose is kind of like ActiveRecord.
Express is kind of like Sinatra.
Jasmine is kind of like RSpec.
Zombie is kind of like Capybara.
Grunt is kind of like Rake.
NPM is kind of like Bundle.
Backbone isn’t really like anything, but at least its MV* pattern is close enough to Rails that I feel at home.
JS is not as friendly an environment as Ruby, where you get to use intuitive syntax, the community is better established, and there are lots and lots of gems available. But it is very fast and scalable, and at least the components feel familiar when transferring from Sinatra and Rails.