HTML and CSS Reference
In-Depth Information
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.
JavaScript developers should feel right at home in Node's evented world. After
all, the browser is evented too, and most JavaScript code is triggered by events.
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
on any JavaScript object; and in Chapter 12, Abstracting Browser Differences: Ajax
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
http://nodejs.org and follow instructions.
14.1.1.1 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
'-- test
'-- chapp
1. http://www.virtualbox.org/
2. http://www.ubuntu.com/
 
Search WWH ::




Custom Search