Learning about Node.js (via Tekpub)

I am a huge fan of Tekpub. This is my second yearly subscription and I am constantly happy with how much value I gain from going through site.

This weekend I thought it would be fun to take some time and work through the NodeJS series using an instance of Ubuntu (12.04.2 LTS) hosted on Azure. I ran into a couple issues while following along with the screencasts and Node.js v0.10.9; here they are in case anyone else finds it useful :)

General

There are a few options in PuTTY that will make your experience a little more friendly:

  • Window/Appearance > change to Consolas 12-point (or your favour fixed-width font) with ClearType enabled
  • Window / Translation > set Remote character set to UTF-8 (this makes tree lines appear normal)
  • Window > Colours > make sure the first three checkboxes are checked

Episode 1

Not an issue at all, actually, but since loading a web browser to test the “Hello from Node” session over SSH is a bit tough, try this instead. Here’s the sample code

var http = require("http");
http.createServer(function(req,res) {
        res.end("Hello from Node");
}).listen(3333);

  1. After saving the file and exiting vm, run node demo.js &'. This starts node running in the background
  2. “Navigate” to the website using curl. curl localhost:3333
  3. You should see the response “Hello from Node”
  4. To stop the node server, run pkill –n node

To install mocha globally, you will most like need to prepend the command with sudo, i.e. sudo npm install –g mocha

Episode 4  - Modules

The current version of NodeJS will not allow for spaces in package names (e.g. “Rob’s Awesome Auth Thing”).

(I went back to double-check on this and it seems to work just fine now, but I’ve also installed more Node modules. Coincidence?)

Episode 5 – Data

Redis

Installing redis itself is ‘sudo apt-get install redis-server’ (not sudo apt-get install redis)

Installing redis for Node (npm install hiredis redis)

will probably fail with the following error

gyp ERR! build error
gyp ERR! stack Error: not found: make

sudo apt-get install build-essential

MongoDb

sudo apt-get install mongodb

If you try to run it right away, you may get this error

azureuser@jedi-slingshot:~/NodeDemo$ mongo
MongoDB shell version: 2.0.4
connecting to: test
Sun Jun  2 17:13:35 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
I followed the instructions here (http://stackoverflow.com/a/6848840/9913) to get it working. Presumably if there’s more work, one of those answers on the page will help you out.

PostgreSQL

You need to install it first (otherwise ‘npm install pg’ will fail)

/bin/sh: 1: pgconfig: not found
gyp: Call to 'pg
config --libdir' returned exit status 127. while trying to load binding.gyp
gyp ERR! configure error

sudo apt-get install postgresql

> pg@1.1.2 install /home/azureuser/NodeDemo/node_modules/pg
> node-gyp rebuild || (exit 0)

You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
gyp: Call to 'pg_config --libdir' returned exit status 1. while trying to load binding.gyp

sudo apt-get install libpq-dev

[Update Jan 2013: sorry, the installation instructions for this module are probably now out-of-date again.]

comments powered by Disqus