|
@ -30,7 +30,7 @@ body { |
|
|
} |
|
|
} |
|
|
#toc a { color: #777; } |
|
|
#toc a { color: #777; } |
|
|
|
|
|
|
|
|
h1, h2, h3 { color: inherit; } |
|
|
h1, h2, h3 { color: #aaf; } |
|
|
|
|
|
|
|
|
h1 { |
|
|
h1 { |
|
|
margin: 2em 0; |
|
|
margin: 2em 0; |
|
@ -42,7 +42,6 @@ h1 { |
|
|
h1 a { color: inherit; } |
|
|
h1 a { color: inherit; } |
|
|
|
|
|
|
|
|
h2 { |
|
|
h2 { |
|
|
margin: 2em 0; |
|
|
|
|
|
font-size: 45px; |
|
|
font-size: 45px; |
|
|
line-height: inherit; |
|
|
line-height: inherit; |
|
|
font-weight: bold; |
|
|
font-weight: bold; |
|
@ -58,13 +57,18 @@ h3 { |
|
|
pre, code { |
|
|
pre, code { |
|
|
font-family: monospace; |
|
|
font-family: monospace; |
|
|
font-size: 13pt; |
|
|
font-size: 13pt; |
|
|
|
|
|
color: #eae; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pre { |
|
|
|
|
|
padding-left: 2em; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
dl { |
|
|
dl { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
dt { |
|
|
dt { |
|
|
color: #f55; |
|
|
color: #aaf; |
|
|
font-weight: bold; |
|
|
font-weight: bold; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -76,6 +80,11 @@ dd { |
|
|
a { color: #cd5; text-decoration: none; } |
|
|
a { color: #cd5; text-decoration: none; } |
|
|
a:hover { text-decoration: underline; } |
|
|
a:hover { text-decoration: underline; } |
|
|
|
|
|
|
|
|
|
|
|
.highlight { |
|
|
|
|
|
background: #733; |
|
|
|
|
|
padding: 0.2em 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
</style> |
|
|
</style> |
|
|
<title>node.js</title> |
|
|
<title>node.js</title> |
|
|
<body> |
|
|
<body> |
|
@ -104,10 +113,11 @@ a:hover { text-decoration: underline; } |
|
|
|
|
|
|
|
|
<h1><a href="http://tinyclouds.org/node">Node</a></h1> |
|
|
<h1><a href="http://tinyclouds.org/node">Node</a></h1> |
|
|
|
|
|
|
|
|
<p id="introduction"> Node is a purely evented I/O framework for <a |
|
|
<p id="introduction"> Node is a purely asynchronous I/O framework for <a |
|
|
href="http://code.google.com/p/v8/">V8 javascript</a>. For example, this is a |
|
|
href="http://code.google.com/p/v8/">V8 javascript</a>. |
|
|
simple web server which responds with "Hello World" after waiting two |
|
|
|
|
|
seconds: |
|
|
<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"> |
|
|
<pre class="sh_javascript"> |
|
|
new node.http.Server(function (msg) { |
|
|
new node.http.Server(function (msg) { |
|
|
setTimeout(function () { |
|
|
setTimeout(function () { |
|
@ -351,7 +361,8 @@ msg.sendHeader( 200 |
|
|
|
|
|
|
|
|
<h3 id="modules">Modules</h3> |
|
|
<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> |
|
|
<pre> |
|
|
include("mjsunit"); |
|
|
include("mjsunit"); |
|
|
|
|
|
|
|
@ -362,14 +373,17 @@ function onLoad () { |
|
|
<p>Here the module <code>mjsunit</code> has provided the function |
|
|
<p>Here the module <code>mjsunit</code> has provided the function |
|
|
<code>assertEquals()</code>. |
|
|
<code>assertEquals()</code>. |
|
|
|
|
|
|
|
|
<p> The file <code>mjsunit.js</code> must be in the same directory for this |
|
|
<p> The module file, <code>mjsunit.js</code>, must be in the same directory |
|
|
to work. The <code>include()</code> function will take all the exported |
|
|
as <code>foo.js</code> for <code>include()</code> to work. The |
|
|
objects from the file and put them into the global namespace. Because file |
|
|
<code>include()</code> function will insert all the exported objects from the |
|
|
loading does not happen instantaniously, and because Node has a policy of |
|
|
module into the global namespace. |
|
|
never blocking, the callback <code>onLoad()</code> is provided to notify the |
|
|
|
|
|
user when all the exported functions are completely loaded. |
|
|
<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 |
|
|
Let's look at how <code>mjsunit.js</code> does this |
|
|
|
|
|
|
|
|
<pre> |
|
|
<pre> |
|
@ -381,7 +395,7 @@ function deepEquals (a, b) { |
|
|
// ... |
|
|
// ... |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
exports.assertEquals = function (expected, found, name_opt) { |
|
|
<span class="highlight">exports</span>.assertEquals = function (expected, found, name_opt) { |
|
|
if (!deepEquals(found, expected)) { |
|
|
if (!deepEquals(found, expected)) { |
|
|
fail(expected, found, name_opt); |
|
|
fail(expected, found, name_opt); |
|
|
} |
|
|
} |
|
@ -393,7 +407,7 @@ exported and remain private to the module. |
|
|
<p> In addition to <code>include()</code> a module can use |
|
|
<p> In addition to <code>include()</code> a module can use |
|
|
<code>require()</code>. Instead of loading the exported objects into the |
|
|
<code>require()</code>. Instead of loading the exported objects into the |
|
|
global namespace, it will return a namespace object. Again, the members of |
|
|
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: |
|
|
<code>onLoad()</code> callback is made. For example: |
|
|
<pre> |
|
|
<pre> |
|
|
var mjsunit = require("mjsunit"); |
|
|
var mjsunit = require("mjsunit"); |
|
|