Node Tutorial - hello world

This post is the first in a series that explains how I am building out a web app using node and express.

The object of this first post is just to get to a working "localhost:4000/hello.txt". It's a condensed version of the first part of the express guide. I don't go into a lot of detail about the hows and whys, but if you follow along on your Mac, you should be able to get where I'm going. All along the way I am saving files to github, but I'm not showing that part because it's not necessary for my purposes here -- I assume you know how to use git.

Install Node

brew install node

Build the directory structure of the project

export TOPDIR=/some/path/to/your/project
mkdir -p $TOPDIR

Create the package.json file

It should look like this:

  "name": "my-project",
  "description": "my project",
  "version": "0.0.1",
  "dependencies": {
    "express": "4.x"

Install local copies of dependencies

npm install

Create the simplest app possible

It should look like this:

var express = require('express');
var app = express();
app.get('/hello.txt', function(req, res){
      res.send('Hello World');
var server = app.listen(3000, function() {
        console.log('Listening on port %d', server.address().port);

Start it up

Once you've started the app, point your browser at http://localhost:3000/hello.txt to see 'Hello World'.

node app