First steps with CoffeeScript

less than 1 minute read

I’ve been intending to use CoffeeScript for ages now. Rails adopting it was the kick up the arse I needed to go and learn it. I got a copy of CoffeeScript as a Christmas present from Orlaith and started reading it today. First thing was to rewrite the well known Node.JS simple server in CoffeeScript. Hardly a massive task but good first steps to get a feel for the syntax etc.

Below is the CoffeeScript for the simple node server (

http = require 'http'

http.createServer (req, res) ->
  res.writeHead 200, 'Content-Type': 'text/plain'
  res.end 'Hello, World!'
.listen 8000

console.log 'Server running at'

And here is the compiled javascript from running coffee -c

(function() {
  var http;

  http = require('http');

  http.createServer(function(req, res) {
    res.writeHead(200, {
      'Content-Type': 'text/plain'
    return res.end('Hello, World!');

  console.log('Server running at');


I know which version I prefer.