HTML and CSS Reference
I named the project “chapp,” as in “chat app.” The deps directory is for third
party dependencies; the other two should be self-explanatory.
126.96.36.199 Testing Framework
Node has a CommonJS compliant Assert module, but in line with the low-level
focus of Node, it only provides a few assertions. No test runner, no test cases, and
no high-level testing utilities; just the bare knuckles assertions, enabling framework
authors to build their own.
For this chapter we will be using a version of a small testing framework called
Nodeunit. Nodeunit was originally designed to look like QUnit, jQuery's unit testing
framework. I have added some bells and whistles to it to bring it slightly closer to
JsTestDriver in style, so testing with it should look familiar.
The version of Nodeunit used for this chapter can be downloaded from the
book's website, 3 and should live in deps/nodeunit . Listing 14.2 shows a small
script to help run tests. Save it in ./run _ tests and make it executable with
chmod +x run _ tests .
Listing 14.2 Script to run tests
require.paths.push( __ dirname);
require.paths.push( __ dirname + "/deps");
require.paths.push( __ dirname + "/lib");
14.1.2 Starting Point
There's a lot of code ahead of us, and to get us started I will provide a basic starting
point, consisting of a small HTTP server and a convenient script to start it. We will
then proceed top-down, actually taking the server for a spin halfway.
188.8.131.52 The Server
To create an HTTP server in Node we need the http module and its create-
Server method. This method accepts a function, which will be attached as a
request listener . CommonJS modules will be properly introduced in a moment,