Skip to content
This repository
tree: 9c97b1db30
Fetching contributors…

Cannot retrieve contributors at this time

file 207 lines (180 sloc) 7.989 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
<!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;
    }
    </style>
    <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="style.css" />
    <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>
        <li><a href="#demo">Demo</a></li>
        <li><a href="#community">Community</a></li>
        <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">
        Purely event-based I/O for
        <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>
      
      <pre>
node.http.createServer(function (req, res) {
  setTimeout(function () {
    res.sendHeader(200, [["Content-Type", "text/plain"]]);
    res.sendBody("Hello World");
    res.finish();
  }, 2000);
}).listen(8000);
puts("Server running at http://127.0.0.1:8000/");</pre>
      
      <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>
      
      <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
        programs. In the above example, the 2 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.
      </p>
      
      <p>
        This is in contrast to today's more common model where OS threads
        are employed for concurrency. Thread-based networking
        <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 -->
        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. 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.
      </p>

      <p>
        Node is similar in design to systems like Ruby's
        <a href="http://rubyeventmachine.com/">Event Machine</a>
        or Python's <a href="http://twistedmatrix.com/">Twisted</a>.
        Node takes the event model a bit further. For example, 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 call like
        <code>EventMachine::run()</code>. In Node it works differently.
        By default Node enters the event loop after executing the input
        script. Node exits the event loop when there are no more callbacks
        to perform. Like in traditional browser javascript, the event loop
        is hidden from the user.
      </p>
      
      <p>
        Node's HTTP API has grown out of my difficulties developing and
        working with web servers. For example, streaming data through
        most web frameworks is impossible. Or the oft-made false
        assumption that all message headers have unique fields. Node
        attempts to correct these and other problems in its API. Coupled
        with Node's purely evented infrastructure, it will make a more
        comprehensive foundation for future web libraries/frameworks.
      </p>
      
      <p>
        <i>
          But what about multiple-processor concurrency? Threads are
          necessary to scale programs to multi-core computers.
        </i>
        The name <i>Node</i> should give some hint at how it is envisioned
        being used. 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 the future, I'd like Node to be able to
        spawn new processes (probably 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.
      </p>

      <h2 id="download">Download</h2>

      <p>
        <a href="http://github.com/ry/node/tree/master">git repo</a>
      </p>
      <p>
        2009.08.22
        <a href="http://s3.amazonaws.com/four.livejournal/20090822/node-0.1.6.tar.gz">node-0.1.6.tar.gz</a>
      </p>

      <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
        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 dependencies.
      </p>
      
      <pre class="sh_none">
./configure
make
make install</pre>

      <p>
        Then have a look at the <a href="api.html">API documentation</a>.
      </p>

      <p>To run the tests</p>

      <pre class="sh_none">make test</pre>
      
      <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>

      <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>

      <p>
        For real-time discussion, check irc.freenode.net #node.js.
      </p>
    </div>
  </body>
</html>
Something went wrong with that request. Please try again.