It has been a couple of months in our journey to build the open learn project. Our deadline to launch the first version is November 1st (I know, coming up soon). I feel like we’ve made some headway on the technical side and it sure took me some time. Below is a summary of some tips and resources I found to help build a database driven, MVC based web app.
There are few different pieces I had to get comfortable with to build an end-to-end app. Here’s what I have for now:
- Node (obviously)
- Express (light framework on top of Node to help create a basic server – e.g. accept and make basic http requests)
- Jade (templating engine that makes writing html and logic together much easier)
- MongoDB (the noSQL database that was recently in the news)
- Mongoose (which helps Express talk to MongoDB)
Given that I have never built an end-to-end web application, there were three distinct stages for me as I was getting started:
- Hello world
- Let’s play
- Piecing together the puzzle
So, the first thing I (and I am guessing anyone new to programming) wanted to do was to print Hello World using Node. Turned out, it wasn’t that complicated. I followed the steps exactly as on Heroku’s Node getting started guide (except the database part, which we will get to later) and managed to get the basic app running that outputted “Hello World” to localhost and to the app on Heroku ([app name].herokuapp.com).
Rather quickly after installing the basic app, I realized I didn’t know what to do next. I had hello world on the screen, but what next?
It took me a couple of hours to build the sample app – a simple uploader that would let you upload an image and then display that image. It was fairly basic, however, would break some times (I believe the ebook was a little outdated). This was actually a blessing in disguise as I had to figure out what was broken, hit the forums and Express API and understand why it was broken.
Ultiately, I had the basic app up and running. I could now play with uploading and displaying images. Yay! :)
Piecing together the puzzle
Finally, I could see light at the end of the tunnel. I had a basic app which did more than Hello World! :)
The next stage for me was to understand how to go from this basic app all the way to what I had in mind for Open Learn. I went back to the Professional Node.js book (remember? the one with lots more detail). Chapter 21 of this book goes through building an app using Express so I thought it would be to go back to that. I started structuring my app using that resource and got a little further. However, yet again, it seemed like the book offered way more than what I needed at that time.
I was looking to setup the basic structure of my app and what I was getting from that book was a lot more sophisticated stuff like sessions and authentication.
So, I looked elsewhere and came across two resources on the web (long live the web!):
Given how light Express is, the sample app (MVC) on Github was a great inspiration for my setup. I quickly refactored and restructured my code accordingly. The video tutorials above were a life saver too in reinforcing a lot of basic concepts and explaining stuff I wasn’t entirely sure about in a working environment.
Ultimately, I had to choose which database to use. Initially I had setup Postgres (just because at my previous startup we had used that and I remembered it). In the spirit, however, of learning something new, I decided to go with MongoDB. A quick web search helped me narrow down MongoHQ as the service to go with (given I was on Heroku). Setting up MongoHQ was dead simple too with the instructions here and here.
Finally, after multiple weekends, I now had a very basic MVC database driven web app running locally as well as on Heroku. Couldn’t be happier. The next few weekends will be dedicated to putting the polishing touches, and actually getting this app to launch state.