}
#toc a { color: #777; }
-h1, h2, h3 { color: inherit; }
+h1, h2, h3 { color: #aaf; }
h1 {
margin: 2em 0;
h1 a { color: inherit; }
h2 {
- margin: 2em 0;
font-size: 45px;
line-height: inherit;
font-weight: bold;
pre, code {
font-family: monospace;
font-size: 13pt;
+ color: #eae;
+}
+
+pre {
+ padding-left: 2em;
}
dl {
}
dt {
- color: #f55;
+ color: #aaf;
font-weight: bold;
}
a { color: #cd5; text-decoration: none; }
a:hover { text-decoration: underline; }
+.highlight {
+ background: #733;
+ padding: 0.2em 0;
+}
+
</style>
<title>node.js</title>
<body>
<h1><a href="http://tinyclouds.org/node">Node</a></h1>
-<p id="introduction"> Node is a purely evented I/O framework for <a
- href="http://code.google.com/p/v8/">V8 javascript</a>. For example, this is a
-simple web server which responds with "Hello World" after waiting two
-seconds:
+<p id="introduction"> Node is a purely asynchronous I/O framework for <a
+ href="http://code.google.com/p/v8/">V8 javascript</a>.
+
+<p>This is an example of a web server written with Node which responds with
+"Hello World" after waiting two seconds:
<pre class="sh_javascript">
new node.http.Server(function (msg) {
setTimeout(function () {
<h3 id="modules">Modules</h3>
-<p>Node has simple module loading. Here is an example of loading a module:
+<p>Node has simple module loading. Here is an example. This is the file
+<code>foo.js</code>:
<pre>
include("mjsunit");
<p>Here the module <code>mjsunit</code> has provided the function
<code>assertEquals()</code>.
-<p> The file <code>mjsunit.js</code> must be in the same directory for this
-to work. The <code>include()</code> function will take all the exported
-objects from the file and put them into the global namespace. Because file
-loading does not happen instantaniously, and because Node has a policy of
-never blocking, the callback <code>onLoad()</code> is provided to notify the
-user when all the exported functions are completely loaded.
+<p> The module file, <code>mjsunit.js</code>, must be in the same directory
+as <code>foo.js</code> for <code>include()</code> to work. The
+<code>include()</code> function will insert all the exported objects from the
+module into the global namespace.
+
+<p> Because file loading does not happen instantaneously, and because Node
+has a policy of never blocking, the callback <code>onLoad()</code> is
+provided to notify the user when all the exported functions are completely
+loaded.
-<p> To export an object, add to the special object <code>exports</code>.
+<p> To export an object, add to the special object <code class="highlight">exports</code>.
Let's look at how <code>mjsunit.js</code> does this
<pre>
// ...
}
-exports.assertEquals = function (expected, found, name_opt) {
+<span class="highlight">exports</span>.assertEquals = function (expected, found, name_opt) {
if (!deepEquals(found, expected)) {
fail(expected, found, name_opt);
}
<p> In addition to <code>include()</code> a module can use
<code>require()</code>. Instead of loading the exported objects into the
global namespace, it will return a namespace object. Again, the members of
-the namespace object can only be guarenteed to exist after the
+the namespace object can only be guaranteed to exist after the
<code>onLoad()</code> callback is made. For example:
<pre>
var mjsunit = require("mjsunit");
NODE_SET_PROTOTYPE_METHOD(constructor_template, "fullClose", v8FullClose);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "forceClose", v8ForceClose);
- target->Set(String::NewSymbol("TCPConnection"), constructor_template->GetFunction());
+ target->Set(String::NewSymbol("Connection"), constructor_template->GetFunction());
}
Connection::Connection (Handle<Object> handle, Handle<Function> protocol_class)
NODE_SET_PROTOTYPE_METHOD(constructor_template, "listen", v8Listen);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "close", v8Close);
- target->Set(String::NewSymbol("TCPServer"), constructor_template->GetFunction());
+ target->Set(String::NewSymbol("Server"), constructor_template->GetFunction());
}
Acceptor::Acceptor (Handle<Object> handle, Handle<Function> protocol_class, Handle<Object> options)