HTML and CSS Reference
As we discussed in Chapter 13, StreamingDatawithAjax andComet, web servers
that allocate one thread per connection, such as Apache httpd, do not scale well in
terms of concurrency. Even more so when concurrent connections are long lived.
When Node receives a request, it will start listening for certain events, such
as data ready from a database, the file system, or a network service. It then goes
to sleep. Once the data is ready, events notify the request, which then finishes the
connection. This is all seamlessly handled by Node's event loop.
Just take a look at the code we've developed throughout this topic. In Chapter 10,
Feature Detection, we wrote a cross browser way to assign event handlers to DOM
elements; in Chapter 11, The Observer Pattern, we wrote a library to observe events
and Chapter 13, Streaming Data with Ajax and Comet, we used callbacks to asyn-
chronously fetch data from the server.
14.1.1 Setting up the Environment
Setting up Node is pretty straightforward, unless you're on Windows. Unfortunately,
at the time of writing, Node does not run on Windows. It is possible to get it
running in Cygwin with some effort, but I think the easiest approach for Windows
users is to download and install the free virtualization software VirtualBox 1 and
run, e.g., Ubuntu Linux 2 inside it. To install Node, download the source from
22.214.171.124 Directory Structure
The project directory structure can be seen in Listing 14.1.
Listing 14.1 Initial directory structure
chris@laptop:~/projects/chapp $ tree
| -- deps
| -- lib
| '-- chapp