Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 94e627dc32
Fetching contributors…

Cannot retrieve contributors at this time

230 lines (201 sloc) 10.335 kb
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<style type="text/css">
ul {
padding: 0;
margin: 0;
<script type="text/javascript" src="sh_main.js"></script>
<script type="text/javascript" src="sh_javascript.min.js"></script>
<link type="text/css" rel="stylesheet" href="pipe.css" />
<link type="text/css" rel="stylesheet" href="sh_vim-dark.css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<body onload="sh_highlightDocument();">
<div id="toc">
<li><a href="#audience">Audience</a></li>
<li><a href="#about">About</a></li>
<li><a href="#download">Download</a></li>
<li><a href="#build">Build</a></li>
<li><a href="#demo">Demo</a></li>
<li><a href="#community">Community</a></li>
<li><a href="#benchmarks">Benchmarks</a></li>
<li><a href="api.html">Documentation</a></li>
<div id="content">
<h1><a href="">Node</a></h1>
<p id="introduction">
Evented I/O for
<a href="">V8 javascript</a>.
An example of a web server written with Node which responds with
"Hello World" after waiting two seconds:
node.http.createServer(function (req, res) {
setTimeout(function () {
res.sendHeader(200, {"Content-Type": "text/plain"});
res.sendBody("Hello World");
}, 2000);
puts("Server running at");</pre>
To run the server, put the code into a file
<code>example.js</code> and execute it with the <code>node</code>
<pre class="sh_none">
% /usr/local/bin/node example.js
Server running at</pre>
See the <a href="api.html">API documentation</a> for more
<h2 id="audience">Audience</h2>
<p>This project is for those interested in</p>
<li>server-side javascript</li>
<li>developing evented servers</li>
<li>developing new web frameworks</li>
<h2 id="about">About</h2>
Node's goal is to provide an easy way to build scalable network
programs. In the above example, the two second delay does not
prevent the server from handling new requests. Node tells the
operating system (through <code>epoll</code>, <code>kqueue</code>,
<code class="sh_none">/dev/poll</code>, or <code>select</code>)
that it should be notified when the 2 seconds are up or if a new
connection is made&mdash;then it goes to sleep. If someone new
connects, then it executes the callback, if the timeout expires,
it executes the inner callback. Each connection is only a small
heap allocation.
This is in contrast to today's more common concurrency model where
OS threads are employed. Thread-based networking
<a href="">is</a>
<a href="">relatively</a>
<a href="">inefficient</a>
<!-- TODO needs links -->
and very difficult to use.
Node will show much better memory efficiency under high-loads
<!-- TODO benchmark -->
than systems which allocate 2mb thread stacks for each connection.
Furthermore, users of Node are free from worries of dead-locking
the process&mdash;there are no locks. Almost no function in Node
directly performs I/O, so the process never blocks. Because
nothing blocks, less-than-expert programmers are able to develop
fast systems.
Node is similar in design to and inflused by systems like Ruby's <a
href="">Event Machine</a> or Python's <a
href="">Twisted</a>. Node takes the event
model a bit further&mdash;it presents the event loop as a language
construct instead of as a library. In other systems there is always
a blocking call to start the event-loop. Typically one defines
behavior through callbacks at the beginning of a script and at the
end starts a server through a blocking call like
<code>EventMachine::run()</code>. In Node there is no such
start-the-event-loop call. Node simply enters the event loop after
executing the input script. Node exits the event loop when there are
no more callbacks to perform. This behavior is like browser
javascript&mdash;the event loop is hidden from the user.
HTTP is a first class protocol in Node. Node's HTTP library has
grown out of the author's experiences developing and working with
web servers. For example, streaming data through most web frameworks
is impossible. Node attempts to correct these problems in its HTTP
<a href="">parser</a>
and API. Coupled with Node's purely evented infrastructure, it makes
a good foundation for web libraries or frameworks.
But what about multiple-processor concurrency? Threads are
necessary to scale programs to multi-core computers.
Processes are necessary to scale to multi-core computers, not
memory-sharing threads. The fundamentals of scalable systems are
fast networking and non-blocking design&mdash;the rest is message
passing. In future versions, Node will be able to fork new
processes (using the <a
href=""> Web
Workers API </a>), but this is something that fits well into the
current design.
<h2 id="download">Download</h2>
<a href="">git repo</a>
<a href="">node-0.1.9.tar.gz</a>
<h2 id="build">Build</h2>
Node eventually wants to support all POSIX operating systems
(including Windows with MinGW) but at the moment it is only being
tested on <b>Linux</b>, <b>Macintosh</b>, and <b>FreeBSD</b>. The
build system requires Python 2.4 or better. V8, on which Node is
built, supports only IA-32 and ARM processors. V8 is included in the
Node distribution. There are no other dependencies.
<pre class="sh_none">
make install</pre>
Then have a look at the <a href="api.html">API documentation</a>.
<p>To run the tests</p>
<pre class="sh_none">make test</pre>
<h2 id="demo">Demo</h2>
A chat room demo is running at <a
href=""></a>. The
source code for the chat room is at <a
The chat room is not stable and might occasionally be down.
<h2 id="community">Community</h2>
For help and discussion subscribe to the mailing list at
<a href=""></a>
or send an email to <a href=""></a>.
For real-time discussion, check #node.js.
<p> Here are some projects/libraries which are using/for Node.js</p>
<li><a href="">redis-node-client</a>, <a href="">node-json-rpc</a> , <a href="">node-sandbox</a> &#8212; by Brian Hammond / Fictorial</li>
<li><a href="">pubsub</a> &#8212; by Malte Ubl</li>
<li><a href="">frisbee</a> &#8212; A clone of the Disqus blog commenting system, by Urban Hafner</li>
<li><a href="">hxV8</a> &#8212; the haXe &rarr; javascript compiler with modifications to use node I/O. by blackdog66</li>
<li><a href="">node_chat</a> by ry (live demo at <a href=""></a>)</li>
<li><a href="">node-couch</a> &#8212; a CouchDB connector</li>
<li><a href="">express</a> &#8212; a Sinatra clone</li>
<li><a href="">node-tyrant</a> &#8212; An implementation of the Tokyo Tyrant network protocol for the Node.js</li>
<li><a href="">coltrane</a> &#8212; A try at a higher level library/framework for node.js web development</li>
<li><a href="">vroom</a> &#8212; A simple resource oriented web framework built on top of Node.js</li>
<li><a href="">postgres-js</a> &#8212; Postgres protocol implemented in JS</li>
<li><a href="">optparse-js</a> &#8212; Option Parser in JS</li>
<li><a href="">node_postgres</a> &#8212; C binding to libpg (postgres)</li>
<h2 id="benchmarks">Benchmarks</h2>
2009.09.06 <a href="">narwhal, node, v8cgi, thin/eventmachine</a>
Jump to Line
Something went wrong with that request. Please try again.