Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
244 lines (206 sloc) 9.24 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="image/x-icon" rel="icon" href="favicon.ico" />
<link type="image/x-icon" rel="shortcut icon" href="favicon.ico" />
<link type="text/css" rel="stylesheet" href="pipe.css" />
<link type="text/css" rel="stylesheet" href="sh_vim-dark.css" />
<link rel="alternate"
title="node blog"
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<div id="toc">
<li><a href="#download">Download</a></li>
<li><a href="">ChangeLog</a></li>
<li><a href="#about">About</a></li>
<li><a href="">v0.4.10 docs</a></li>
<li><a href="">v0.5.1 docs</a></li>
<li><a href="">Wiki</a></li>
<li><a href="">Blog</a></li>
<li><a href="">Community</a></li>
<li><a href="">Demo</a></li>
<li><a href="/logos/">Logos</a></li>
<li><a href="">Jobs</a></li>
<ol><!-- JOBS --><!-- JOBS --></ol>
<div id="content">
<!-- <h1><a href="">Node</a></h1> -->
<br /><br />
<img id="logo" src="logo.png" alt="node.js"/>
<p id="introduction">
Evented I/O for
<a href="">V8 JavaScript</a>.
An example of a web server written in Node which responds with
"Hello World" for every request.
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "");
console.log('Server running at');
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">
% node example.js
Server running at</pre>
Here is an example of a simple TCP server which listens on port 1337
and echoes whatever you send it:
var net = require('net');
var server = net.createServer(function (socket) {
socket.write("Echo server\r\n");
server.listen(1337, "");
See the <a href="/docs">API documentation</a> for more
Go to <a href="">the Wiki</a> for lots more information.
<h2 id="video">Introduction</h2>
<iframe title="YouTube video player" width="640" height="390"
src="" frameborder="0"
<h2 id="download">Download</h2>
<a href="">git repo</a>
<p>2011.07.19 v0.4.10 (stable)
<ul class="release">
<li><a href=""><code>node-v0.4.10.tar.gz</code> Source Code</a>
<li><a href="">Documentation</a>
<p>2011.07.14 v0.5.1 (unstable)
<ul class="release">
<li><a href=""><code>node-v0.5.1.tar.gz</code> Source code</a>
<li><a href=""><code>node.exe</code> Windows executable</a>
<li><a href="">Documentation</a>
<p>Historical: <a href="">versions</a>, <a href="">docs</a></p>
For build instructions see
<a href=""></a>
<h2 id="about">About</h2>
Node's goal is to provide an easy way to build scalable network
programs. In the "hello world" web server example above, many
client connections can be handled concurrently. 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 a new connection is made, and
then it goes to sleep. If someone new connects, then it executes
the 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 is relatively
inefficient and very difficult to use. See:
<a href="">this</a> and
<a href="">this.</a>
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 influenced 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? Aren't threads
necessary to scale programs to multi-core computers?
You can start new processes via <code>child_process.fork()</code>
these other processes will be scheduled in parallel.
See also:
<li><a href="">slides</a> from JSConf 2009</li>
<li><a href="">slides</a> from JSConf 2010</li>
<li><a href="">video</a> from a talk at Yahoo in May 2010</li>
<div style="float: right;">
title='JS String match'><img
src='' height='150' width='180'
alt='JS String match'/></a>
<a href=""><img src="sponsored.png" height="58" width="120"/></a>
<div style="clear: both; font-size: 8pt">
Copyright 2010 Joyent, Inc
Node.js is a trademark of Joyent, Inc.
See the <a href="trademark-policy.pdf">trademark policy</a>
for more information.
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ?
"https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "' type='text/javascript'%3E%3C/script%3E"));
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-10874194-2");
} catch(err) {}</script>
<script type="text/javascript">highlight(undefined, undefined, 'pre');</script>
Jump to Line
Something went wrong with that request. Please try again.