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 

AnDevCon talk on Fragments

I gave a talk on Android Fragments on May 29, 2014 at AnDevCon in Boston. The talk was well attended and well received. You can download the slide deck from the presentation if you like.

Life used to be simple. We had Activities and they were good. You could define all of your app's UI in a layout and animate it in an Activity. Then Apple brought out the iPad and Google answered with Honeycomb. Things got complex. Google realized that tablets would drive the need for developers to reuse parts of their UI, and the answer was the Fragment class. Fragments enable developers to use bits of UI along with the associated business logic in various parts of their app or even in multiple apps.

The Slide deck has a matching github repository that has several really useful example projects in it. The easiest way to build the examples is with Android Studio and gradle.


This example app uses native fragments to demonstrate several concepts:

  1. Dynamic vs Static Fragments: Static fragments are created with the <fragment> tag in a layout. Dynamic fragments are added at run time to a <frame> tag.
  2. Using a Bundle to store Activity state information throughout the Activity's lifecycle.
  3. The interrelationship of the Activity lifecycle with the Fragment lifecycle. There is a really useful set of classes (CallLogger, LoggedActivity and LoggedFragment) that enable you to log calls from lifecycle events without adding any code to your Activities and Fragments themselves.
  4. How the Back button and configuration changes (screen rotation) affect the Activity and Fragment lifecycles.


This example app demonstrates five styles of communicating data between Activities and Fragments.

Fragment Communication Chart

  • ActivityIntent - How to communicate to a fragment through the Intent that started the Activity.
  • FactoryMethod - Communicate build arguments to a Fragment in a way that will survive the Activity and Fragment lifecycles.
  • ObserverPattern - Two way communication between any combination of multiple Fragments and Activities using the standard Java Observer pattern.
  • LayoutElements - Communicate static build arguments to a Fragment by placing them in the Layout.
  • SetArguments - Using the setArguments call on the Fragment itself to give it arguments available to it during the entire lifecycle.
  • LocalBroadcast - Available only when using the Support Library, LocalBroadcast enables the Observer Pattern without the need for the participants to keep track of Observers.


This project is just like the fragment-comms project except that it uses the support library.


The hall-of-mirrors example demonstrates that Fragments can be nested within other Fragments.

AnDevCon talk on Android Studio

I gave a talk on Android Studio on May 28, 2014 at AnDevCon in Boston. The talk was well attended and well received. You can download the slide deck from the presentation if you like.

This post reemphasizes my main point during the talk.

The best reason to switch to Android Studio today is Gradle integration.

Even though it's still considered Alpha software (as of 6/5/2014), the Android Gradle plugin is ready for prime time, and is much better than the current Android Ant plugin. Gradle builds are somewhat faster than Ant builds, and there are a lot more features. The best reason to use Gradle with Android Studio is the you only have to worry about one build. Normally you have to get your command line build working if you want continuous integration, and your IDE build is separate. It's not difficult to maintain both on simple projects, but on complex projects it can be tedious. Adding a new library can easily break everyone's IDE build, so there is a tendency to leave things alone once a project gets to a certain size.

Because Android Studio uses your Gradle project to build, once you have the Gradle build working, you also have an Android Studio project set up. All the developer has to do is import the top level build.gradle file and away he goes.

Blogging With Github Pages and Poole's Hyde Theme

Note: As of 6/2/2014, this post is still a work in progress

My new blog is built with Github Pages and Jekyll using Poole's Hyde template and the Disqus discussion system.

This article is the first post, and in it I describe how I went from zero to a nice developer web site.


jeckyll serve -w # serve the blog locally # http://localhost:4000