mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
230 lines
10 KiB
230 lines
10 KiB
16 years ago
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||
|
<head>
|
||
|
<style type="text/css">
|
||
|
ul {
|
||
|
padding: 0;
|
||
|
margin: 0;
|
||
|
}
|
||
15 years ago
|
</style>
|
||
16 years ago
|
<script type="text/javascript" src="sh_main.js"></script>
|
||
|
<script type="text/javascript" src="sh_javascript.min.js"></script>
|
||
15 years ago
|
<link type="text/css" rel="stylesheet" href="pipe.css" />
|
||
16 years ago
|
<link type="text/css" rel="stylesheet" href="sh_vim-dark.css" />
|
||
|
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||
|
<title>node.js</title>
|
||
|
</head>
|
||
|
<body onload="sh_highlightDocument();">
|
||
|
<div id="toc">
|
||
|
<ol>
|
||
|
<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>
|
||
16 years ago
|
<li><a href="#demo">Demo</a></li>
|
||
16 years ago
|
<li><a href="#community">Community</a></li>
|
||
15 years ago
|
<li><a href="#benchmarks">Benchmarks</a></li>
|
||
16 years ago
|
<li><a href="api.html">Documentation</a></li>
|
||
|
</ol>
|
||
|
</div>
|
||
|
<div id="content">
|
||
|
|
||
|
<h1><a href="http://tinyclouds.org/node">Node</a></h1>
|
||
|
|
||
|
<p id="introduction">
|
||
15 years ago
|
Evented I/O for
|
||
16 years ago
|
<a href="http://code.google.com/p/v8/">V8 javascript</a>.
|
||
|
</p>
|
||
|
|
||
|
<p>
|
||
|
An example of a web server written with Node which responds with
|
||
|
"Hello World" after waiting two seconds:
|
||
|
</p>
|
||
15 years ago
|
|
||
16 years ago
|
<pre>
|
||
16 years ago
|
node.http.createServer(function (req, res) {
|
||
16 years ago
|
setTimeout(function () {
|
||
15 years ago
|
res.sendHeader(200, {"Content-Type": "text/plain"});
|
||
16 years ago
|
res.sendBody("Hello World");
|
||
|
res.finish();
|
||
16 years ago
|
}, 2000);
|
||
16 years ago
|
}).listen(8000);
|
||
16 years ago
|
puts("Server running at http://127.0.0.1:8000/");</pre>
|
||
15 years ago
|
|
||
16 years ago
|
<p>
|
||
|
To run the server, put the code into a file
|
||
|
<code>example.js</code> and execute it with the <code>node</code>
|
||
|
program
|
||
|
</p>
|
||
|
<pre class="sh_none">
|
||
|
% /usr/local/bin/node example.js
|
||
|
Server running at http://127.0.0.1:8000/</pre>
|
||
15 years ago
|
|
||
16 years ago
|
<p>
|
||
|
See the <a href="api.html">API documentation</a> for more
|
||
|
examples.
|
||
|
</p>
|
||
|
|
||
|
<h2 id="audience">Audience</h2>
|
||
|
|
||
|
<p>This project is for those interested in</p>
|
||
|
<ul>
|
||
|
<li>server-side javascript</li>
|
||
|
<li>developing evented servers</li>
|
||
|
<li>developing new web frameworks</li>
|
||
|
</ul>
|
||
|
|
||
|
<h2 id="about">About</h2>
|
||
|
|
||
|
<p>
|
||
|
Node's goal is to provide an easy way to build scalable network
|
||
15 years ago
|
programs. In the above example, the two second delay does not
|
||
16 years ago
|
prevent the server from handling new requests. Node tells the
|
||
|
operating system (through <code>epoll</code>, <code>kqueue</code>,
|
||
15 years ago
|
<code class="sh_none">/dev/poll</code>, or <code>select</code>)
|
||
16 years ago
|
that it should be notified when the 2 seconds are up or if a new
|
||
|
connection is made—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.
|
||
|
</p>
|
||
15 years ago
|
|
||
16 years ago
|
<p>
|
||
15 years ago
|
This is in contrast to today's more common concurrency model where
|
||
|
OS threads are employed. Thread-based networking
|
||
16 years ago
|
<a href="http://www.sics.se/~joe/apachevsyaws.html">is</a>
|
||
|
<a href="http://www.kegel.com/c10k.html">relatively</a>
|
||
|
<a href="http://bulk.fefe.de/scalable-networking.pdf">inefficient</a>
|
||
|
<!-- TODO needs links -->
|
||
15 years ago
|
and very difficult to use.
|
||
16 years ago
|
|
||
15 years ago
|
Node will show much better memory efficiency under high-loads
|
||
16 years ago
|
<!-- TODO benchmark -->
|
||
|
than systems which allocate 2mb thread stacks for each connection.
|
||
|
|
||
|
Furthermore, users of Node are free from worries of dead-locking
|
||
15 years ago
|
the process—there are no locks. Almost no function in Node
|
||
16 years ago
|
directly performs I/O, so the process never blocks. Because
|
||
|
nothing blocks, less-than-expert programmers are able to develop
|
||
|
fast systems.
|
||
|
</p>
|
||
|
|
||
|
<p>
|
||
15 years ago
|
Node is similar in design to and inflused by systems like Ruby's <a
|
||
15 years ago
|
href="http://rubyeventmachine.com/">Event Machine</a> or Python's <a
|
||
|
href="http://twistedmatrix.com/">Twisted</a>. Node takes the event
|
||
15 years ago
|
model a bit further—it presents the event loop as a language
|
||
|
construct instead of as a library. In other systems there is always
|
||
15 years ago
|
a blocking call to start the event-loop. Typically one defines
|
||
|
behavior through callbacks at the beginning of a script and at the
|
||
15 years ago
|
end starts a server through a blocking call like
|
||
15 years ago
|
<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—the event loop is hidden from the user.
|
||
16 years ago
|
</p>
|
||
15 years ago
|
|
||
16 years ago
|
<p>
|
||
15 years ago
|
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="http://github.com/ry/http-parser/tree/master">parser</a>
|
||
|
and API. Coupled with Node's purely evented infrastructure, it makes
|
||
|
a good foundation for web libraries or frameworks.
|
||
16 years ago
|
</p>
|
||
15 years ago
|
|
||
16 years ago
|
<p>
|
||
|
<i>
|
||
|
But what about multiple-processor concurrency? Threads are
|
||
|
necessary to scale programs to multi-core computers.
|
||
|
</i>
|
||
15 years ago
|
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—the rest is message
|
||
|
passing. In future versions, Node will be able to fork new
|
||
|
processes (using the <a
|
||
|
href="http://www.whatwg.org/specs/web-workers/current-work/"> Web
|
||
|
Workers API </a>), but this is something that fits well into the
|
||
|
current design.
|
||
16 years ago
|
</p>
|
||
|
|
||
|
<h2 id="download">Download</h2>
|
||
|
|
||
|
<p>
|
||
16 years ago
|
<a href="http://github.com/ry/node/tree/master">git repo</a>
|
||
16 years ago
|
</p>
|
||
15 years ago
|
<p>
|
||
15 years ago
|
2009.09.05
|
||
|
<a href="http://s3.amazonaws.com/four.livejournal/20090905/node-0.1.9.tar.gz">node-0.1.9.tar.gz</a>
|
||
15 years ago
|
</p>
|
||
16 years ago
|
|
||
|
<h2 id="build">Build</h2>
|
||
|
|
||
|
<p>
|
||
|
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
|
||
16 years ago
|
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
|
||
15 years ago
|
Node distribution. There are no other dependencies.
|
||
16 years ago
|
</p>
|
||
15 years ago
|
|
||
16 years ago
|
<pre class="sh_none">
|
||
16 years ago
|
./configure
|
||
16 years ago
|
make
|
||
16 years ago
|
make install</pre>
|
||
16 years ago
|
|
||
16 years ago
|
<p>
|
||
|
Then have a look at the <a href="api.html">API documentation</a>.
|
||
|
</p>
|
||
16 years ago
|
|
||
16 years ago
|
<p>To run the tests</p>
|
||
16 years ago
|
|
||
16 years ago
|
<pre class="sh_none">make test</pre>
|
||
15 years ago
|
|
||
16 years ago
|
<h2 id="demo">Demo</h2>
|
||
|
<p>
|
||
|
A chat room demo is running at <a
|
||
|
href="http://chat.tinyclouds.org">chat.tinyclouds.org</a>. The
|
||
|
source code for the chat room is at <a
|
||
|
href="http://github.com/ry/node_chat/tree/master">http://github.com/ry/node_chat</a>.
|
||
|
The chat room is not stable and might occasionally be down.
|
||
|
</p>
|
||
16 years ago
|
|
||
16 years ago
|
<h2 id="community">Community</h2>
|
||
|
<p>
|
||
|
For help and discussion subscribe to the mailing list at
|
||
|
<a href="http://groups.google.com/group/nodejs">http://groups.google.com/group/nodejs</a>
|
||
|
or send an email to <a href="mailto:nodejs+subscribe@googlegroups.com">nodejs+subscribe@googlegroups.com</a>.
|
||
|
</p>
|
||
16 years ago
|
|
||
16 years ago
|
<p>
|
||
16 years ago
|
For real-time discussion, check irc.freenode.net #node.js.
|
||
16 years ago
|
</p>
|
||
15 years ago
|
|
||
|
<p> Here are some projects/libraries which are using/for Node.js</p>
|
||
|
<ul>
|
||
|
<li><a href="http://github.com/fictorial/redis-node-client/tree/master">redis-node-client</a>, <a href="http://github.com/fictorial/node-json-rpc/tree/master">node-json-rpc</a> , <a href="http://github.com/fictorial/node-sandbox/tree/master">node-sandbox</a> — by Brian Hammond / Fictorial</li>
|
||
|
<li><a href="http://www.nonblocking.io/2009/06/scalable-pubsub-with-nodejs.html">pubsub</a> — by Malte Ubl</li>
|
||
|
<li><a href="http://github.com/ujh/frisbee/tree/master">frisbee</a> — A clone of the Disqus blog commenting system, by Urban Hafner</li>
|
||
|
<li><a href="http://github.com/blackdog66/hxV8/tree/master">hxV8</a> — the haXe → javascript compiler with modifications to use node I/O. by blackdog66</li>
|
||
|
<li><a href="http://github.com/ry/node_chat">node_chat</a> by ry (live demo at <a href="http://chat.tinyclouds.org">chat.tinyclouds.org</a>)</li>
|
||
|
<li><a href="http://github.com/sixtus/node-couch/tree/master">node-couch</a> — a CouchDB connector</li>
|
||
|
<li><a href="http://github.com/visionmedia/express/tree/master">express</a> — a Sinatra clone</li>
|
||
|
<li><a href="http://github.com/waveto/node-tyrant/tree/master">node-tyrant</a> — An implementation of the Tokyo Tyrant network protocol for the Node.js</li>
|
||
|
<li><a href="http://github.com/ujh/coltrane/tree/master">coltrane</a> — A try at a higher level library/framework for node.js web development</li>
|
||
|
<li><a href="http://github.com/raycmorgan/vroom/tree/master">vroom</a> — A simple resource oriented web framework built on top of Node.js</li>
|
||
|
<li><a href="http://github.com/creationix/postgres-js/tree/master">postgres-js</a> — Postgres protocol implemented in JS</li>
|
||
|
<li><a href="http://github.com/jfd/optparse-js/tree/master">optparse-js</a> — Option Parser in JS</li>
|
||
|
<li><a href="http://github.com/ry/node_postgres">node_postgres</a> — C binding to libpg (postgres)</li>
|
||
|
</ul>
|
||
|
<h2 id="benchmarks">Benchmarks</h2>
|
||
|
<p>
|
||
|
2009.09.06 <a href="http://four.livejournal.com/1019177.html">narwhal, node, v8cgi, thin/eventmachine</a>
|
||
|
</p>
|
||
16 years ago
|
</div>
|
||
|
</body>
|
||
16 years ago
|
</html>
|