Welcome to mirror list, hosted at ThFree Co, Russian Federation.

index.html « doc - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 113d05620940afa3b04b8d6dd61c4ce591def032 (plain)
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<!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="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"
          type="application/rss+xml"
          title="node blog"
          href="http://feeds.feedburner.com/nodejs/123123123"/>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>node.js</title>
  </head>
  <body>
    <div id="toc">
      <ol>
        <li><a href="#download">Download</a></li>
        <li><a href="https://github.com/joyent/node/wiki/ChangeLog">ChangeLog</a></li>
        <li><a href="#about">About</a></li>
        <li><a href="http://nodejs.org/docs/v0.4.11/api">v0.4.11 docs</a></li>
        <li><a href="http://nodejs.org/docs/v0.5.6/api">v0.5.6 docs</a></li>
        <br/>
        <li><a href="https://github.com/joyent/node/wiki">Wiki</a></li>
        <li><a href="http://blog.nodejs.org/">Blog</a></li>
        <li><a href="https://github.com/joyent/node/wiki/Community">Community</a></li>
        <li><a href="http://chat.nodejs.org/">Demo</a></li>
        <li><a href="/logos/">Logos</a></li>
        <li><a href="http://jobs.nodejs.org/">Jobs</a></li>
        <ol><!-- JOBS --><!-- JOBS --></ol>
      </ol>
    </div>
    <div id="content">

      <!-- <h1><a href="http://nodejs.org/">Node</a></h1> -->
      <br /><br />
      <img id="logo" src="logo.png" alt="node.js"/>

      <p id="introduction">
        Evented I/O for
        <a href="http://code.google.com/p/v8/">V8 JavaScript</a>.
      </p>

      <p>
        An example of a web server written in Node which responds with
        "Hello World" for every request.
      </p>

      <pre>
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
</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">
% node example.js
Server running at http://127.0.0.1:1337/</pre>

      <p>
        Here is an example of a simple TCP server which listens on port 1337
        and echoes whatever you send it:
      </p>

      <pre>
var net = require('net');

var server = net.createServer(function (socket) {
  socket.write("Echo server\r\n");
  socket.pipe(socket);
});

server.listen(1337, "127.0.0.1");
</pre>

      <p>
        See the <a href="/docs">API documentation</a> for more
        examples.
      </p>


      <p>
        Go to <a href="https://github.com/joyent/node/wiki">the Wiki</a> for lots more information.
      </p>

      <h2 id="video">Introduction</h2>

      <iframe title="YouTube video player" width="640" height="390"
        src="http://www.youtube.com/embed/jo_B4LTHi3I" frameborder="0"
        allowfullscreen></iframe>

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

      <p>
        <a href="http://github.com/joyent/node/tree/master">git repo</a>
      </p>

      <p>2011.08.17 v0.4.11 (stable)
      <ul class="release">
        <li><a href="http://nodejs.org/dist/node-v0.4.11.tar.gz"><code>node-v0.4.11.tar.gz</code> Source Code</a>
        <li><a href="http://nodejs.org/docs/v0.4.11/api/index.html">Documentation</a>
      </ul>

      <p>2011.09.09 v0.5.6 (unstable)
      <ul class="release">
        <li><a href="http://nodejs.org/dist/v0.5.6/node-v0.5.6.tar.gz"><code>node-v0.5.6.tar.gz</code> Source code</a>
        <li><a href="http://nodejs.org/dist/v0.5.6/node.exe"><code>node.exe</code> Windows executable</a>
        <li><a href="http://nodejs.org/docs/v0.5.6/api/index.html">Documentation</a>
      </ul>


      <p>Historical: <a href="http://nodejs.org/dist">versions</a>, <a href="http://nodejs.org/docs">docs</a></p>

      <p>
        For build instructions see
        <a href="https://github.com/joyent/node/wiki/Installation">https://github.com/joyent/node/wiki/Installation</a>
      </p>


      <h2 id="about">About</h2>

      <p>
        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.
      </p>

      <p>
        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="http://www.kegel.com/c10k.html">this</a> and 
        <a href="http://bulk.fefe.de/scalable-networking.pdf">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.
      </p>

      <p>
        Node is similar in design to and influenced by 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&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.
      </p>

      <p>
        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.
      </p>

      <p>
        <i>
        But what about multiple-processor concurrency? Aren't threads
        necessary to scale programs to multi-core computers?
        </i>
        You can start new processes via <code>child_process.fork()</code>
        these other processes will be scheduled in parallel.
      </p>

      <p>
        See also:
        <ul>
          <li><a href="http://s3.amazonaws.com/four.livejournal/20091117/jsconf.pdf">slides</a> from JSConf 2009</li>
          <li><a href="http://nodejs.org/jsconf2010.pdf">slides</a> from JSConf 2010</li>
          <li><a href="http://www.yuiblog.com/blog/2010/05/20/video-dahl/">video</a> from a talk at Yahoo in May 2010</li>
        </ul>
      </p>


    </div>

    <div style="float: right;">
      <a
        href='https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String'
        title='JS String match'><img
        src='http://static.jsconf.us/promotejsh.gif' height='150' width='180'
        alt='JS String match'/></a>
    </div>

    <a href="http://no.de/"><img src="sponsored.png" height="58" width="120"/></a>

    <div style="clear: both; font-size: 8pt">
      Copyright 2010 Joyent, Inc
      <br/>
      Node.js is a trademark of Joyent, Inc.
      See the <a href="trademark-policy.pdf">trademark policy</a>
      for more information.
    </div>

    <script type="text/javascript">
      var gaJsHost = (("https:" == document.location.protocol) ?
      "https://ssl." : "http://www.");
      document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
      try {
        var pageTracker = _gat._getTracker("UA-10874194-2");
        pageTracker._trackPageview();
        } catch(err) {}</script>
    <script type="text/javascript">highlight(undefined, undefined, 'pre');</script>
  </body>
</html>