From 0 to Node.Js/Jasmine/CoffeeScript in 10m

4 comments
Context/Background
I wanted to get started with Node.js, Jasmine, and CoffeeScript. How to go about it in an Ubuntu system? For some reason installing node.js via sudo apt-get install nodejs (full instructions) didn't work for me. I overcame this by locally compiling it, but then other issues came up as I moved on to Jasmine. It took some trial-and-error time but eventually I zeroed in on the solution. A key part is the installation of npm (a package manager for Node.js).

Starting Point
You have downloaded Node.js source code (here, node-v0.6.10.tar.gz) into your ~/Downloads directory.

From .tar.gz to Jasmine...
mkdir -p /tmp/installation
sudo apt-get install npm
cd /tmp/installation
tar -zxf ~/Downloads/node-v0.6.10.tar.gz 
cd node-v0.6.10/
./configure
make
node -e "console.log('Node.js is up')"
curl https://npmjs.org/install.sh | sudo sh
sudo npm install jasmine-node -g
cat <<EOF > app1.spec.js
var app = require('./app1.js');

describe("my app", function() {
  it("greets you", function() {
    expect(app.helloWorld("Martin")).toEqual("Hello, Martin");
  });
})      
EOF

cat <<EOF > app1.js
exports.helloWorld = function(s) {
  return "Hello, " + s;
}
EOF

jasmine-node app1.spec.js

... to CoffeeScript
sudo npm install -g coffee-script

cat <<"EOF" > app2.spec.coffee
app = require './app2'

describe "my app", -> 
  it "greets you", -> 
    (expect app.helloWorld "Martin").toEqual "Hello, Martin"
EOF

cat <<"EOF" > app2.coffee
exports.helloWorld = (s) ->
  "Hello, " + s;
EOF

jasmine-node --coffee app2.spec.coffee

Final thoughts
This post's goal is to reduce setup time/learning curve such that others can start using these (great) tools right away. As a Node.js noob, I didn't even know that npm exists. I also found it difficult setting up my first toy programs: a Node.js program, a Jasmine spec, a CoffeeScript program, and a Jasmine/CoffeeScript spec. There are syntactic issues and framework issues (such as: Node's require() and exports thingy) which you need to get exactly right  in order to make the pieces fit together. An out-of-the-box running sample - which is what this post tries to provide - can mitigate much of this pain.

I also found it difficult to find good web-pages discussing this process. Thus, for the common good, I will put a few keywords to help future Noobies find it: jasmine node.js coffeescript Ubuntu npm spec installation setup getting started hello world program.