Getting started with Heroku and Node.js

Heroku is a cloud platform supporting Node.js, Ruby, Python, Scala, Clojure and PHP.

The Cloud seems to be the (buzz)word of the year, and Node.js is cool so I wanted to develop a small application as a test.

Note: I develop on OS X and this lightweight tutorial is OS X Lion specific, you probably should read Getting Started with Node.js on Heroku/Cedar, but it dosen’t work out of the box on OS X!

Ok, here we go:

1. Sign up for Heroku
Just go here and do what Heroku ask you to.

2. Install the Heroku toolbelt
You find the toolbelt for OSX here. Download the pkg file and install it.

3. Install Node.js compatible with Heroku
I normally use Homebrew to install software like Node.js, but Heroku don’t support Node.js version 0.6.15 which is what I got from brew.
Here is a list of supported versions on Heroku

The solution is NVM, which may be installed with like this:

git clone git:// ~/.nvm

NVM is implemented as a bash function. Source it in .bash_profile or similar to have nvm available all the time:

. ~/.nvm/

I installed version version 0.4.7 which is the default version on the Heroku Cedar plattform:

nvm install v0.4.7

It is probably no surprise the Node Version Manager can manage different Node.js versions installed on the same machine, but for now one install is great! (running ‘node -v’ should work by now, giving you v0.4.7)

4. Write your web application

As a test, and because I need the data from time to time, I wrote a small application which maps Norwegian postal codes to places:

var express = require('express');
var app = express.createServer(express.logger());
app.get('/', function(request, response) {
        response.send('Hello.  Please give me a Norwegian postal ' +
                      'code (postnummer) and I will give you the place');
app.get('/:pc', function(request, response) {
        if (p.hasOwnProperty(request.params.pc)) {
        else {
                response.send('Invalid postal code (postnummer)',404);
var port = process.env.PORT || 3000;
app.listen(port, function() {
        console.log("Listening on " + port);
// add data here
var p = new Array();
p['0001'] = "OSLO";
p['1300'] = "SANDVIKA";

The p array has close to 4600 elements, and I generate the script with some curl and perl magic. Feel free take a look at my code on GitHub.

5. Create a package.json file

  "name": "node-posten",
  "version": "0.0.1",
  "engines": {
	"node": "0.4.7"
  "dependencies": {
  	"express": "2.2.0"

I have explicit set node and express versions, the defaults should work ok for now though.

6. Install dependencies on your Mac

npm install

This installs the needed libraries into node_modules, a directory I added to .gitignore because it is local to my installation.

7. Declare process type for Foreman

I added this to my Procfile:

web: node web.js

Test the application running on you Mac

foreman start

You should now have your application available on localhost:5000.

http://localhost:5000/1300 gives me ‘SANDVIKA’ *whee!*

8. Commit everything to git

Something like:

git init
git add .
git commit -m "Initial commit"

9. login to Heroku

heroku login

And follow the on screen instructions

9. Deploy to Heroku

Create application on Heroku Cedar:

heroku create --stack cedar

Then push the application to Heroku with pure git:

git push heroku master

I find this way of deploying pure beauty!

10. Scale webprocesses on Heroku

One process is free, and should do the trick for now:

heroku ps:scale web=1

11. Sit back and enjoy your new cloud app

Isn’t it great?

Thank you people over at Heroku!

Posted in Code, Hacking | Tagged , , , , , | Leave a comment

Liverpool and Manchester

Not a football match, but almost the last part of my trip to the United Kingdom.

After Santa Pod I drove east, to Liverpool. Not being av football fan I’m not really sure there were to much to see there, sorry.

I went to the Liverpool Museum, The Beatles Story and just walked around in the city, but didn’t really like it. Don’t know exactly why, I found some nice restaurants in Liverpool Chinatown and a nice pub or two, but ..

Manchester up next!

In Manchester I meat Claudia and Stian Soiland-Reyes and their cute boy Sebastian. Together we got to some location at University of Manchester to celebrate the Mexican independence day; Claudia is from Mexico.

Sebastian, 7 months old, didn’t want to spend the night there, so he and his mother went home quite early, and Stian and I did the celebrating, which included English beer, Mexican food and a least two smashed piñatas before we found a nice English pub for one more beer before it was time to ride the last bus / tram back ‘home’.

The next day Claudia and Stian invited me over for Mexican dinner. Very nice food, and very nice to speak to Stian who I haven’t seen for years (we used to work together in Trondheim)

Thanks Claudia and Stian!

Sorry about the low quality picture; iPhone in the dark …

Posted in Travel | Tagged , , | Leave a comment

FIA/UEM dragracing finals at Santa Pod

After spending one night in the strange town of Weston-super-Mare I drove up to Kettering. A small town located 80 miles from London and close to Santa Pod Raceway where the finals for both FIA (cars) and UEM (motorcycles) European championships are held each year.

Going to the finals was one of the main reasons for this trip, and it was really worth it.

I will not write a lot about results, you can read all about that on, as the nitro smell in the air and all kinds of race cars and bikes blasting down the strip just has to be experienced!

Love it!!

Posted in Motoring, Photo, Travel | Tagged , , , , | Leave a comment