This is part of an ongoing series of posts about Homesick, my bachelor project.

The server side is hosted here.

This is a great opportunity for me to learn both Node.js and get acquainted with server-side programming.

Having said that, I realize that using Node.js might be overkill for something that could be solved with a more low-level approach, but I want to learn Node.js, simple as that!

In order to install Node, you can either download an installer from their website or install it using your favorite package manager. Myself, I used Homebrew on OS X with the command $ brew install node.

I also opted for writing CoffeeScript because I find it a lot of fun! If you don’t know what CoffeeScript is, it’s a language that compiles into JavaScript. Be sure to try it out here!. You can use the NPM (Node Package Manager) that comes bundled with Node to install CoffeeScript using the command $ npm install coffee-script.

As a part of my toolchain, I’m personally a huge fan of rake for setting up tasks.

Here’s the tasks I have set up at the moment:

``` ruby RakeFile https://github.com/ramonh/homesick-server/blob/master/Rakefile Source

task :coffee do puts ‘CoffeeScript compiled!’ if system ‘coffee -c -o js coffee’ end

task :run => [:coffee] do puts ‘Starting server’ system ‘node js/app.js’ end ```

Short and sweet. The first tasks just prints “CoffeeScript compiled!” if the command to compile is successful. The way the coffee command works is it looks at the .coffee files in the coffee folder, and compiles them into the js folder.

What the run task does is it requires the coffee task, that is, it makes sure that the task has been run, and then starts the server with the node command. This takes the compiled app JavaScript file and runs it.

If you’d like to get furher into rake, I highly recommend watching the rake talks by rake’s creator, the late Jim Weirich. Or really, any talks he gave. They’re all wonderful.

Buy me a coffee