API: Move node.puts(), node.exec() and others to /utils.js
This commit is contained in:
parent
c35dfdfd5e
commit
7abad8b7b3
141
doc/api.html
141
doc/api.html
@ -36,7 +36,8 @@ window.onload = function(){generateToc(2)}
|
|||||||
World":</p></div>
|
World":</p></div>
|
||||||
<div class="listingblock">
|
<div class="listingblock">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre><tt>node.http.createServer(function (request, response) {
|
<pre><tt>include("/utils.js");
|
||||||
|
node.http.createServer(function (request, response) {
|
||||||
response.sendHeader(200, {"Content-Type": "text/plain"});
|
response.sendHeader(200, {"Content-Type": "text/plain"});
|
||||||
response.sendBody("Hello World\n");
|
response.sendBody("Hello World\n");
|
||||||
response.finish();
|
response.finish();
|
||||||
@ -59,47 +60,10 @@ of the 16bit javascript string characters. Both are relatively fast—use
|
|||||||
them if you can. <tt>"utf8"</tt> is slower and should be avoided when possible.</p></div>
|
them if you can. <tt>"utf8"</tt> is slower and should be avoided when possible.</p></div>
|
||||||
<div class="paragraph"><p>Unless otherwise noted, functions are all asynchronous and do not block
|
<div class="paragraph"><p>Unless otherwise noted, functions are all asynchronous and do not block
|
||||||
execution.</p></div>
|
execution.</p></div>
|
||||||
<h3 id="_helpers">Helpers</h3><div style="clear:left"></div>
|
<h3 id="_helpers_and_global_variables">Helpers and Global Variables</h3><div style="clear:left"></div>
|
||||||
|
<div class="paragraph"><p>These objects are available to all programs.</p></div>
|
||||||
<div class="dlist"><dl>
|
<div class="dlist"><dl>
|
||||||
<dt class="hdlist1">
|
<dt class="hdlist1">
|
||||||
<tt>puts(string)</tt>
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
<p>
|
|
||||||
Outputs the <tt>string</tt> and a trailing new-line to <tt>stdout</tt>.
|
|
||||||
</p>
|
|
||||||
<div class="paragraph"><p>Everything in node is asynchronous; <tt>puts()</tt> is no exception. This might
|
|
||||||
seem ridiculous but, if for example, one is piping <tt>stdout</tt> into an NFS
|
|
||||||
file, <tt>printf()</tt> will block from network latency. There is an internal
|
|
||||||
queue for <tt>puts()</tt> output, so you can be assured that output will be
|
|
||||||
displayed in the order it was called.</p></div>
|
|
||||||
</dd>
|
|
||||||
<dt class="hdlist1">
|
|
||||||
<tt>node.debug(string)</tt>
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
<p>
|
|
||||||
A synchronous output function. Will block the process and
|
|
||||||
output the string immediately to stdout.
|
|
||||||
</p>
|
|
||||||
</dd>
|
|
||||||
<dt class="hdlist1">
|
|
||||||
<tt>node.inspect(object)</tt>
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
<p>
|
|
||||||
Return a string representation of the <tt>object</tt>. (For debugging.)
|
|
||||||
</p>
|
|
||||||
</dd>
|
|
||||||
<dt class="hdlist1">
|
|
||||||
<tt>print(string)</tt>
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
<p>
|
|
||||||
Like <tt>puts()</tt> but without the trailing new-line.
|
|
||||||
</p>
|
|
||||||
</dd>
|
|
||||||
<dt class="hdlist1">
|
|
||||||
<tt>node.exit(code)</tt>
|
<tt>node.exit(code)</tt>
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
@ -108,33 +72,6 @@ Immediately ends the process with the specified code.
|
|||||||
</p>
|
</p>
|
||||||
</dd>
|
</dd>
|
||||||
<dt class="hdlist1">
|
<dt class="hdlist1">
|
||||||
<tt>node.exec(command)</tt>
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
<p>
|
|
||||||
Executes the command as a child process, buffers the output and returns it
|
|
||||||
in a promise callback.
|
|
||||||
</p>
|
|
||||||
<div class="listingblock">
|
|
||||||
<div class="content">
|
|
||||||
<pre><tt>node.exec("ls /").addCallback(function (stdout, stderr) {
|
|
||||||
puts(stdout);
|
|
||||||
});</tt></pre>
|
|
||||||
</div></div>
|
|
||||||
<div class="ulist"><ul>
|
|
||||||
<li>
|
|
||||||
<p>
|
|
||||||
on success: stdout buffer, stderr buffer
|
|
||||||
</p>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<p>
|
|
||||||
on error: exit code, stdout buffer, stderr buffer
|
|
||||||
</p>
|
|
||||||
</li>
|
|
||||||
</ul></div>
|
|
||||||
</dd>
|
|
||||||
<dt class="hdlist1">
|
|
||||||
<tt>node.cwd()</tt>
|
<tt>node.cwd()</tt>
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
@ -142,9 +79,6 @@ on error: exit code, stdout buffer, stderr buffer
|
|||||||
Returns the current working directory of the process.
|
Returns the current working directory of the process.
|
||||||
</p>
|
</p>
|
||||||
</dd>
|
</dd>
|
||||||
</dl></div>
|
|
||||||
<h3 id="_global_variables">Global Variables</h3><div style="clear:left"></div>
|
|
||||||
<div class="dlist"><dl>
|
|
||||||
<dt class="hdlist1">
|
<dt class="hdlist1">
|
||||||
<tt>ARGV</tt>
|
<tt>ARGV</tt>
|
||||||
</dt>
|
</dt>
|
||||||
@ -179,6 +113,71 @@ browser-side javascript.
|
|||||||
</p>
|
</p>
|
||||||
</dd>
|
</dd>
|
||||||
</dl></div>
|
</dl></div>
|
||||||
|
<h3 id="_utilities">Utilities</h3><div style="clear:left"></div>
|
||||||
|
<div class="paragraph"><p>These function are in <tt>"/utils.js"</tt>. Use <tt>require("/utils.js")</tt> to access them.</p></div>
|
||||||
|
<div class="dlist"><dl>
|
||||||
|
<dt class="hdlist1">
|
||||||
|
<tt>puts(string)</tt>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
<p>
|
||||||
|
Outputs the <tt>string</tt> and a trailing new-line to <tt>stdout</tt>.
|
||||||
|
</p>
|
||||||
|
</dd>
|
||||||
|
<dt class="hdlist1">
|
||||||
|
<tt>print(string)</tt>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
<p>
|
||||||
|
Like <tt>puts()</tt> but without the trailing new-line.
|
||||||
|
</p>
|
||||||
|
</dd>
|
||||||
|
<dt class="hdlist1">
|
||||||
|
<tt>debug(string)</tt>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
<p>
|
||||||
|
A synchronous output function. Will block the process and
|
||||||
|
output the string immediately to stdout.
|
||||||
|
</p>
|
||||||
|
</dd>
|
||||||
|
<dt class="hdlist1">
|
||||||
|
<tt>inspect(object)</tt>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
<p>
|
||||||
|
Return a string representation of the <tt>object</tt>. (For debugging.)
|
||||||
|
</p>
|
||||||
|
</dd>
|
||||||
|
<dt class="hdlist1">
|
||||||
|
<tt>exec(command)</tt>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
<p>
|
||||||
|
Executes the command as a child process, buffers the output and returns it
|
||||||
|
in a promise callback.
|
||||||
|
</p>
|
||||||
|
<div class="listingblock">
|
||||||
|
<div class="content">
|
||||||
|
<pre><tt>include("/utils.js");
|
||||||
|
exec("ls /").addCallback(function (stdout, stderr) {
|
||||||
|
puts(stdout);
|
||||||
|
});</tt></pre>
|
||||||
|
</div></div>
|
||||||
|
<div class="ulist"><ul>
|
||||||
|
<li>
|
||||||
|
<p>
|
||||||
|
on success: stdout buffer, stderr buffer
|
||||||
|
</p>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<p>
|
||||||
|
on error: exit code, stdout buffer, stderr buffer
|
||||||
|
</p>
|
||||||
|
</li>
|
||||||
|
</ul></div>
|
||||||
|
</dd>
|
||||||
|
</dl></div>
|
||||||
<h3 id="_events">Events</h3><div style="clear:left"></div>
|
<h3 id="_events">Events</h3><div style="clear:left"></div>
|
||||||
<div class="paragraph"><p>Many objects in Node emit events: a TCP server emits an event each time
|
<div class="paragraph"><p>Many objects in Node emit events: a TCP server emits an event each time
|
||||||
there is a connection, a child process emits an event when it exits. All
|
there is a connection, a child process emits an event when it exits. All
|
||||||
@ -1944,7 +1943,7 @@ init (Handle<Object> target)
|
|||||||
<div id="footer">
|
<div id="footer">
|
||||||
<div id="footer-text">
|
<div id="footer-text">
|
||||||
Version 0.1.12<br />
|
Version 0.1.12<br />
|
||||||
Last updated 2009-09-27 12:27:16 CEST
|
Last updated 2009-09-28 12:04:19 CEST
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
79
doc/api.txt
79
doc/api.txt
@ -16,6 +16,7 @@ An example of a web server written with Node which responds with "Hello
|
|||||||
World":
|
World":
|
||||||
|
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
|
include("/utils.js");
|
||||||
node.http.createServer(function (request, response) {
|
node.http.createServer(function (request, response) {
|
||||||
response.sendHeader(200, {"Content-Type": "text/plain"});
|
response.sendHeader(200, {"Content-Type": "text/plain"});
|
||||||
response.sendBody("Hello World\n");
|
response.sendBody("Hello World\n");
|
||||||
@ -45,56 +46,16 @@ Unless otherwise noted, functions are all asynchronous and do not block
|
|||||||
execution.
|
execution.
|
||||||
|
|
||||||
|
|
||||||
=== Helpers
|
=== Helpers and Global Variables
|
||||||
|
|
||||||
+puts(string)+::
|
|
||||||
Outputs the +string+ and a trailing new-line to +stdout+.
|
|
||||||
+
|
|
||||||
Everything in node is asynchronous; +puts()+ is no exception. This might
|
|
||||||
seem ridiculous but, if for example, one is piping +stdout+ into an NFS
|
|
||||||
file, +printf()+ will block from network latency. There is an internal
|
|
||||||
queue for +puts()+ output, so you can be assured that output will be
|
|
||||||
displayed in the order it was called.
|
|
||||||
|
|
||||||
|
|
||||||
+node.debug(string)+::
|
|
||||||
A synchronous output function. Will block the process and
|
|
||||||
output the string immediately to stdout.
|
|
||||||
|
|
||||||
|
|
||||||
+node.inspect(object)+ ::
|
|
||||||
Return a string representation of the +object+. (For debugging.)
|
|
||||||
|
|
||||||
|
|
||||||
+print(string)+::
|
|
||||||
Like +puts()+ but without the trailing new-line.
|
|
||||||
|
|
||||||
|
These objects are available to all programs.
|
||||||
|
|
||||||
+node.exit(code)+::
|
+node.exit(code)+::
|
||||||
Immediately ends the process with the specified code.
|
Immediately ends the process with the specified code.
|
||||||
|
|
||||||
+node.exec(command)+::
|
|
||||||
Executes the command as a child process, buffers the output and returns it
|
|
||||||
in a promise callback.
|
|
||||||
+
|
|
||||||
----------------------------------------
|
|
||||||
node.exec("ls /").addCallback(function (stdout, stderr) {
|
|
||||||
puts(stdout);
|
|
||||||
});
|
|
||||||
----------------------------------------
|
|
||||||
+
|
|
||||||
- on success: stdout buffer, stderr buffer
|
|
||||||
- on error: exit code, stdout buffer, stderr buffer
|
|
||||||
|
|
||||||
|
|
||||||
+node.cwd()+::
|
+node.cwd()+::
|
||||||
Returns the current working directory of the process.
|
Returns the current working directory of the process.
|
||||||
|
|
||||||
|
|
||||||
=== Global Variables
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+ARGV+ ::
|
+ARGV+ ::
|
||||||
An array containing the command line arguments.
|
An array containing the command line arguments.
|
||||||
|
|
||||||
@ -109,6 +70,40 @@ A special global object. The +process+ object is like the +window+ object of
|
|||||||
browser-side javascript.
|
browser-side javascript.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
=== Utilities
|
||||||
|
|
||||||
|
These function are in +"/utils.js"+. Use +require("/utils.js")+ to access them.
|
||||||
|
|
||||||
|
+puts(string)+::
|
||||||
|
Outputs the +string+ and a trailing new-line to +stdout+.
|
||||||
|
|
||||||
|
+print(string)+::
|
||||||
|
Like +puts()+ but without the trailing new-line.
|
||||||
|
|
||||||
|
+debug(string)+::
|
||||||
|
A synchronous output function. Will block the process and
|
||||||
|
output the string immediately to stdout.
|
||||||
|
|
||||||
|
+inspect(object)+ ::
|
||||||
|
Return a string representation of the +object+. (For debugging.)
|
||||||
|
|
||||||
|
+exec(command)+::
|
||||||
|
Executes the command as a child process, buffers the output and returns it
|
||||||
|
in a promise callback.
|
||||||
|
+
|
||||||
|
----------------------------------------
|
||||||
|
include("/utils.js");
|
||||||
|
exec("ls /").addCallback(function (stdout, stderr) {
|
||||||
|
puts(stdout);
|
||||||
|
});
|
||||||
|
----------------------------------------
|
||||||
|
+
|
||||||
|
- on success: stdout buffer, stderr buffer
|
||||||
|
- on error: exit code, stdout buffer, stderr buffer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
=== Events
|
=== Events
|
||||||
|
|
||||||
Many objects in Node emit events: a TCP server emits an event each time
|
Many objects in Node emit events: a TCP server emits an event each time
|
||||||
|
159
doc/api.xml
159
doc/api.xml
@ -12,7 +12,8 @@
|
|||||||
<refsynopsisdiv id="_synopsis">
|
<refsynopsisdiv id="_synopsis">
|
||||||
<simpara>An example of a web server written with Node which responds with "Hello
|
<simpara>An example of a web server written with Node which responds with "Hello
|
||||||
World":</simpara>
|
World":</simpara>
|
||||||
<screen>node.http.createServer(function (request, response) {
|
<screen>include("/utils.js");
|
||||||
|
node.http.createServer(function (request, response) {
|
||||||
response.sendHeader(200, {"Content-Type": "text/plain"});
|
response.sendHeader(200, {"Content-Type": "text/plain"});
|
||||||
response.sendBody("Hello World\n");
|
response.sendBody("Hello World\n");
|
||||||
response.finish();
|
response.finish();
|
||||||
@ -31,57 +32,12 @@ of the 16bit javascript string characters. Both are relatively fast—use
|
|||||||
them if you can. <literal>"utf8"</literal> is slower and should be avoided when possible.</simpara>
|
them if you can. <literal>"utf8"</literal> is slower and should be avoided when possible.</simpara>
|
||||||
<simpara>Unless otherwise noted, functions are all asynchronous and do not block
|
<simpara>Unless otherwise noted, functions are all asynchronous and do not block
|
||||||
execution.</simpara>
|
execution.</simpara>
|
||||||
<refsect2 id="_helpers">
|
<refsect2 id="_helpers_and_global_variables">
|
||||||
<title>Helpers</title>
|
<title>Helpers and Global Variables</title>
|
||||||
|
<simpara>These objects are available to all programs.</simpara>
|
||||||
<variablelist>
|
<variablelist>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term>
|
<term>
|
||||||
<literal>puts(string)</literal>
|
|
||||||
</term>
|
|
||||||
<listitem>
|
|
||||||
<simpara>
|
|
||||||
Outputs the <literal>string</literal> and a trailing new-line to <literal>stdout</literal>.
|
|
||||||
</simpara>
|
|
||||||
<simpara>Everything in node is asynchronous; <literal>puts()</literal> is no exception. This might
|
|
||||||
seem ridiculous but, if for example, one is piping <literal>stdout</literal> into an NFS
|
|
||||||
file, <literal>printf()</literal> will block from network latency. There is an internal
|
|
||||||
queue for <literal>puts()</literal> output, so you can be assured that output will be
|
|
||||||
displayed in the order it was called.</simpara>
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
<varlistentry>
|
|
||||||
<term>
|
|
||||||
<literal>node.debug(string)</literal>
|
|
||||||
</term>
|
|
||||||
<listitem>
|
|
||||||
<simpara>
|
|
||||||
A synchronous output function. Will block the process and
|
|
||||||
output the string immediately to stdout.
|
|
||||||
</simpara>
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
<varlistentry>
|
|
||||||
<term>
|
|
||||||
<literal>node.inspect(object)</literal>
|
|
||||||
</term>
|
|
||||||
<listitem>
|
|
||||||
<simpara>
|
|
||||||
Return a string representation of the <literal>object</literal>. (For debugging.)
|
|
||||||
</simpara>
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
<varlistentry>
|
|
||||||
<term>
|
|
||||||
<literal>print(string)</literal>
|
|
||||||
</term>
|
|
||||||
<listitem>
|
|
||||||
<simpara>
|
|
||||||
Like <literal>puts()</literal> but without the trailing new-line.
|
|
||||||
</simpara>
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
<varlistentry>
|
|
||||||
<term>
|
|
||||||
<literal>node.exit(code)</literal>
|
<literal>node.exit(code)</literal>
|
||||||
</term>
|
</term>
|
||||||
<listitem>
|
<listitem>
|
||||||
@ -92,32 +48,6 @@ Immediately ends the process with the specified code.
|
|||||||
</varlistentry>
|
</varlistentry>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term>
|
<term>
|
||||||
<literal>node.exec(command)</literal>
|
|
||||||
</term>
|
|
||||||
<listitem>
|
|
||||||
<simpara>
|
|
||||||
Executes the command as a child process, buffers the output and returns it
|
|
||||||
in a promise callback.
|
|
||||||
</simpara>
|
|
||||||
<screen>node.exec("ls /").addCallback(function (stdout, stderr) {
|
|
||||||
puts(stdout);
|
|
||||||
});</screen>
|
|
||||||
<itemizedlist>
|
|
||||||
<listitem>
|
|
||||||
<simpara>
|
|
||||||
on success: stdout buffer, stderr buffer
|
|
||||||
</simpara>
|
|
||||||
</listitem>
|
|
||||||
<listitem>
|
|
||||||
<simpara>
|
|
||||||
on error: exit code, stdout buffer, stderr buffer
|
|
||||||
</simpara>
|
|
||||||
</listitem>
|
|
||||||
</itemizedlist>
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
<varlistentry>
|
|
||||||
<term>
|
|
||||||
<literal>node.cwd()</literal>
|
<literal>node.cwd()</literal>
|
||||||
</term>
|
</term>
|
||||||
<listitem>
|
<listitem>
|
||||||
@ -126,11 +56,6 @@ Returns the current working directory of the process.
|
|||||||
</simpara>
|
</simpara>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
</variablelist>
|
|
||||||
</refsect2>
|
|
||||||
<refsect2 id="_global_variables">
|
|
||||||
<title>Global Variables</title>
|
|
||||||
<variablelist>
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term>
|
<term>
|
||||||
<literal>ARGV</literal>
|
<literal>ARGV</literal>
|
||||||
@ -174,6 +99,80 @@ browser-side javascript.
|
|||||||
</varlistentry>
|
</varlistentry>
|
||||||
</variablelist>
|
</variablelist>
|
||||||
</refsect2>
|
</refsect2>
|
||||||
|
<refsect2 id="_utilities">
|
||||||
|
<title>Utilities</title>
|
||||||
|
<simpara>These function are in <literal>"/utils.js"</literal>. Use <literal>require("/utils.js")</literal> to access them.</simpara>
|
||||||
|
<variablelist>
|
||||||
|
<varlistentry>
|
||||||
|
<term>
|
||||||
|
<literal>puts(string)</literal>
|
||||||
|
</term>
|
||||||
|
<listitem>
|
||||||
|
<simpara>
|
||||||
|
Outputs the <literal>string</literal> and a trailing new-line to <literal>stdout</literal>.
|
||||||
|
</simpara>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
<varlistentry>
|
||||||
|
<term>
|
||||||
|
<literal>print(string)</literal>
|
||||||
|
</term>
|
||||||
|
<listitem>
|
||||||
|
<simpara>
|
||||||
|
Like <literal>puts()</literal> but without the trailing new-line.
|
||||||
|
</simpara>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
<varlistentry>
|
||||||
|
<term>
|
||||||
|
<literal>debug(string)</literal>
|
||||||
|
</term>
|
||||||
|
<listitem>
|
||||||
|
<simpara>
|
||||||
|
A synchronous output function. Will block the process and
|
||||||
|
output the string immediately to stdout.
|
||||||
|
</simpara>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
<varlistentry>
|
||||||
|
<term>
|
||||||
|
<literal>inspect(object)</literal>
|
||||||
|
</term>
|
||||||
|
<listitem>
|
||||||
|
<simpara>
|
||||||
|
Return a string representation of the <literal>object</literal>. (For debugging.)
|
||||||
|
</simpara>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
<varlistentry>
|
||||||
|
<term>
|
||||||
|
<literal>exec(command)</literal>
|
||||||
|
</term>
|
||||||
|
<listitem>
|
||||||
|
<simpara>
|
||||||
|
Executes the command as a child process, buffers the output and returns it
|
||||||
|
in a promise callback.
|
||||||
|
</simpara>
|
||||||
|
<screen>include("/utils.js");
|
||||||
|
exec("ls /").addCallback(function (stdout, stderr) {
|
||||||
|
puts(stdout);
|
||||||
|
});</screen>
|
||||||
|
<itemizedlist>
|
||||||
|
<listitem>
|
||||||
|
<simpara>
|
||||||
|
on success: stdout buffer, stderr buffer
|
||||||
|
</simpara>
|
||||||
|
</listitem>
|
||||||
|
<listitem>
|
||||||
|
<simpara>
|
||||||
|
on error: exit code, stdout buffer, stderr buffer
|
||||||
|
</simpara>
|
||||||
|
</listitem>
|
||||||
|
</itemizedlist>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
</variablelist>
|
||||||
|
</refsect2>
|
||||||
<refsect2 id="_events">
|
<refsect2 id="_events">
|
||||||
<title>Events</title>
|
<title>Events</title>
|
||||||
<simpara>Many objects in Node emit events: a TCP server emits an event each time
|
<simpara>Many objects in Node emit events: a TCP server emits an event each time
|
||||||
|
@ -41,14 +41,17 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
node.http.createServer(function (req, res) {
|
utils = require("/utils.js");
|
||||||
|
server = node.http.createServer(function (req, res) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
res.sendHeader(200, {"Content-Type": "text/plain"});
|
res.sendHeader(200, {"Content-Type": "text/plain"});
|
||||||
res.sendBody("Hello World");
|
res.sendBody("Hello World");
|
||||||
res.finish();
|
res.finish();
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}).listen(8000);
|
});
|
||||||
puts("Server running at http://127.0.0.1:8000/");</pre>
|
server.listen(8000);
|
||||||
|
utils.puts("Server running at http://127.0.0.1:8000/");</pre>
|
||||||
|
</pre>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
To run the server, put the code into a file
|
To run the server, put the code into a file
|
||||||
|
136
doc/node.1
136
doc/node.1
@ -1,11 +1,11 @@
|
|||||||
.\" Title: node
|
.\" Title: node
|
||||||
.\" Author:
|
.\" Author:
|
||||||
.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
|
.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
|
||||||
.\" Date: 09/27/2009
|
.\" Date: 09/28/2009
|
||||||
.\" Manual:
|
.\" Manual:
|
||||||
.\" Source:
|
.\" Source:
|
||||||
.\"
|
.\"
|
||||||
.TH "NODE" "1" "09/27/2009" "" ""
|
.TH "NODE" "1" "09/28/2009" "" ""
|
||||||
.\" disable hyphenation
|
.\" disable hyphenation
|
||||||
.nh
|
.nh
|
||||||
.\" disable justification (adjust text to left margin only)
|
.\" disable justification (adjust text to left margin only)
|
||||||
@ -18,6 +18,7 @@ An example of a web server written with Node which responds with "Hello World":
|
|||||||
.sp
|
.sp
|
||||||
.RS 4
|
.RS 4
|
||||||
.nf
|
.nf
|
||||||
|
include("/utils\.js");
|
||||||
node\.http\.createServer(function (request, response) {
|
node\.http\.createServer(function (request, response) {
|
||||||
response\.sendHeader(200, {"Content\-Type": "text/plain"});
|
response\.sendHeader(200, {"Content\-Type": "text/plain"});
|
||||||
response\.sendBody("Hello World\en");
|
response\.sendBody("Hello World\en");
|
||||||
@ -40,75 +41,18 @@ Node supports 3 string encodings\. UTF\-8 ("utf8"), ASCII ("ascii"), and Binary
|
|||||||
.sp
|
.sp
|
||||||
Unless otherwise noted, functions are all asynchronous and do not block execution\.
|
Unless otherwise noted, functions are all asynchronous and do not block execution\.
|
||||||
.sp
|
.sp
|
||||||
.SS "Helpers"
|
.SS "Helpers and Global Variables"
|
||||||
.PP
|
These objects are available to all programs\.
|
||||||
puts(string)
|
|
||||||
.RS 4
|
|
||||||
Outputs the
|
|
||||||
string
|
|
||||||
and a trailing new\-line to
|
|
||||||
stdout\.
|
|
||||||
.sp
|
|
||||||
Everything in node is asynchronous;
|
|
||||||
puts()
|
|
||||||
is no exception\. This might seem ridiculous but, if for example, one is piping
|
|
||||||
stdout
|
|
||||||
into an NFS file,
|
|
||||||
printf()
|
|
||||||
will block from network latency\. There is an internal queue for
|
|
||||||
puts()
|
|
||||||
output, so you can be assured that output will be displayed in the order it was called\.
|
|
||||||
.RE
|
|
||||||
.PP
|
|
||||||
node\.debug(string)
|
|
||||||
.RS 4
|
|
||||||
A synchronous output function\. Will block the process and output the string immediately to stdout\.
|
|
||||||
.RE
|
|
||||||
.PP
|
|
||||||
node\.inspect(object)
|
|
||||||
.RS 4
|
|
||||||
Return a string representation of the
|
|
||||||
object\. (For debugging\.)
|
|
||||||
.RE
|
|
||||||
.PP
|
|
||||||
print(string)
|
|
||||||
.RS 4
|
|
||||||
Like
|
|
||||||
puts()
|
|
||||||
but without the trailing new\-line\.
|
|
||||||
.RE
|
|
||||||
.PP
|
.PP
|
||||||
node\.exit(code)
|
node\.exit(code)
|
||||||
.RS 4
|
.RS 4
|
||||||
Immediately ends the process with the specified code\.
|
Immediately ends the process with the specified code\.
|
||||||
.RE
|
.RE
|
||||||
.PP
|
.PP
|
||||||
node\.exec(command)
|
|
||||||
.RS 4
|
|
||||||
Executes the command as a child process, buffers the output and returns it in a promise callback\.
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.nf
|
|
||||||
node\.exec("ls /")\.addCallback(function (stdout, stderr) {
|
|
||||||
puts(stdout);
|
|
||||||
});
|
|
||||||
.fi
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
\h'-04'\(bu\h'+03'on success: stdout buffer, stderr buffer
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
\h'-04'\(bu\h'+03'on error: exit code, stdout buffer, stderr buffer
|
|
||||||
.RE
|
|
||||||
.RE
|
|
||||||
.PP
|
|
||||||
node\.cwd()
|
node\.cwd()
|
||||||
.RS 4
|
.RS 4
|
||||||
Returns the current working directory of the process\.
|
Returns the current working directory of the process\.
|
||||||
.RE
|
.RE
|
||||||
.SS "Global Variables"
|
|
||||||
.PP
|
.PP
|
||||||
ARGV
|
ARGV
|
||||||
.RS 4
|
.RS 4
|
||||||
@ -133,6 +77,56 @@ object is like the
|
|||||||
window
|
window
|
||||||
object of browser\-side javascript\.
|
object of browser\-side javascript\.
|
||||||
.RE
|
.RE
|
||||||
|
.SS "Utilities"
|
||||||
|
These function are in "/utils\.js"\. Use require("/utils\.js") to access them\.
|
||||||
|
.PP
|
||||||
|
puts(string)
|
||||||
|
.RS 4
|
||||||
|
Outputs the
|
||||||
|
string
|
||||||
|
and a trailing new\-line to
|
||||||
|
stdout\.
|
||||||
|
.RE
|
||||||
|
.PP
|
||||||
|
print(string)
|
||||||
|
.RS 4
|
||||||
|
Like
|
||||||
|
puts()
|
||||||
|
but without the trailing new\-line\.
|
||||||
|
.RE
|
||||||
|
.PP
|
||||||
|
debug(string)
|
||||||
|
.RS 4
|
||||||
|
A synchronous output function\. Will block the process and output the string immediately to stdout\.
|
||||||
|
.RE
|
||||||
|
.PP
|
||||||
|
inspect(object)
|
||||||
|
.RS 4
|
||||||
|
Return a string representation of the
|
||||||
|
object\. (For debugging\.)
|
||||||
|
.RE
|
||||||
|
.PP
|
||||||
|
exec(command)
|
||||||
|
.RS 4
|
||||||
|
Executes the command as a child process, buffers the output and returns it in a promise callback\.
|
||||||
|
.sp
|
||||||
|
.RS 4
|
||||||
|
.nf
|
||||||
|
include("/utils\.js");
|
||||||
|
exec("ls /")\.addCallback(function (stdout, stderr) {
|
||||||
|
puts(stdout);
|
||||||
|
});
|
||||||
|
.fi
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
.RS 4
|
||||||
|
\h'-04'\(bu\h'+03'on success: stdout buffer, stderr buffer
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
.RS 4
|
||||||
|
\h'-04'\(bu\h'+03'on error: exit code, stdout buffer, stderr buffer
|
||||||
|
.RE
|
||||||
|
.RE
|
||||||
.SS "Events"
|
.SS "Events"
|
||||||
Many objects in Node emit events: a TCP server emits an event each time there is a connection, a child process emits an event when it exits\. All objects which emit events are are instances of node\.EventEmitter\.
|
Many objects in Node emit events: a TCP server emits an event each time there is a connection, a child process emits an event when it exits\. All objects which emit events are are instances of node\.EventEmitter\.
|
||||||
.sp
|
.sp
|
||||||
@ -153,7 +147,7 @@ All EventEmitters emit the event "newListener" when new listeners are added\.
|
|||||||
.sp
|
.sp
|
||||||
.TS
|
.TS
|
||||||
allbox tab(:);
|
allbox tab(:);
|
||||||
ltB ltB ltB.
|
ltB ltB ltBx.
|
||||||
T{
|
T{
|
||||||
Event
|
Event
|
||||||
T}:T{
|
T}:T{
|
||||||
@ -209,7 +203,7 @@ node\.Promise inherits from node\.eventEmitter\. A promise emits one of two even
|
|||||||
.sp
|
.sp
|
||||||
.TS
|
.TS
|
||||||
allbox tab(:);
|
allbox tab(:);
|
||||||
ltB ltB ltB.
|
ltB ltB ltBx.
|
||||||
T{
|
T{
|
||||||
Event
|
Event
|
||||||
T}:T{
|
T}:T{
|
||||||
@ -308,7 +302,7 @@ Standard I/O is handled through a special object node\.stdio\. stdout and stdin
|
|||||||
.sp
|
.sp
|
||||||
.TS
|
.TS
|
||||||
allbox tab(:);
|
allbox tab(:);
|
||||||
ltB ltB ltB.
|
ltB ltB ltBx.
|
||||||
T{
|
T{
|
||||||
Event
|
Event
|
||||||
T}:T{
|
T}:T{
|
||||||
@ -494,7 +488,7 @@ node.ChildProcess
|
|||||||
.RS
|
.RS
|
||||||
.TS
|
.TS
|
||||||
allbox tab(:);
|
allbox tab(:);
|
||||||
ltB ltB ltB.
|
ltB ltB ltBx.
|
||||||
T{
|
T{
|
||||||
Event
|
Event
|
||||||
T}:T{
|
T}:T{
|
||||||
@ -850,7 +844,7 @@ node.http.Server
|
|||||||
.RS
|
.RS
|
||||||
.TS
|
.TS
|
||||||
allbox tab(:);
|
allbox tab(:);
|
||||||
ltB ltB ltB.
|
ltB ltB ltBx.
|
||||||
T{
|
T{
|
||||||
Event
|
Event
|
||||||
T}:T{
|
T}:T{
|
||||||
@ -934,7 +928,7 @@ This object is created internally by a HTTP server\(emnot by the user\(emand pas
|
|||||||
.sp
|
.sp
|
||||||
.TS
|
.TS
|
||||||
allbox tab(:);
|
allbox tab(:);
|
||||||
ltB ltB ltB.
|
ltB ltB ltBx.
|
||||||
T{
|
T{
|
||||||
Event
|
Event
|
||||||
T}:T{
|
T}:T{
|
||||||
@ -1191,7 +1185,7 @@ This object is created internally and returned from the request methods of a nod
|
|||||||
.sp
|
.sp
|
||||||
.TS
|
.TS
|
||||||
allbox tab(:);
|
allbox tab(:);
|
||||||
ltB ltB ltB.
|
ltB ltB ltBx.
|
||||||
T{
|
T{
|
||||||
Event
|
Event
|
||||||
T}:T{
|
T}:T{
|
||||||
@ -1289,7 +1283,7 @@ This object is created internally and passed to the "response" event\.
|
|||||||
.sp
|
.sp
|
||||||
.TS
|
.TS
|
||||||
allbox tab(:);
|
allbox tab(:);
|
||||||
ltB ltB ltB.
|
ltB ltB ltBx.
|
||||||
T{
|
T{
|
||||||
Event
|
Event
|
||||||
T}:T{
|
T}:T{
|
||||||
@ -1398,7 +1392,7 @@ server\.listen(7000, "localhost");
|
|||||||
.RE
|
.RE
|
||||||
.TS
|
.TS
|
||||||
allbox tab(:);
|
allbox tab(:);
|
||||||
ltB ltB ltB.
|
ltB ltB ltBx.
|
||||||
T{
|
T{
|
||||||
Event
|
Event
|
||||||
T}:T{
|
T}:T{
|
||||||
@ -1480,7 +1474,7 @@ This object is used as a TCP client and also as a server\-side socket for node\.
|
|||||||
.sp
|
.sp
|
||||||
.TS
|
.TS
|
||||||
allbox tab(:);
|
allbox tab(:);
|
||||||
ltB ltB ltB.
|
ltB ltB ltBx.
|
||||||
T{
|
T{
|
||||||
Event
|
Event
|
||||||
T}:T{
|
T}:T{
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
// A repl library that you can include in your own code to get a runtime
|
// A repl library that you can include in your own code to get a runtime
|
||||||
// interface to your program. Just require("/repl.js").
|
// interface to your program. Just require("/repl.js").
|
||||||
|
|
||||||
|
var utils = require("utils.js");
|
||||||
|
|
||||||
puts("Type '.help' for options.");
|
puts("Type '.help' for options.");
|
||||||
|
|
||||||
node.stdio.open();
|
node.stdio.open();
|
||||||
@ -42,7 +44,7 @@ function readline (cmd) {
|
|||||||
with (exports.scope) {
|
with (exports.scope) {
|
||||||
var ret = eval(buffered_cmd);
|
var ret = eval(buffered_cmd);
|
||||||
exports.scope['_'] = ret;
|
exports.scope['_'] = ret;
|
||||||
puts(node.inspect(ret));
|
utils.p(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffered_cmd = '';
|
buffered_cmd = '';
|
||||||
|
28
src/node.js
28
src/node.js
@ -15,30 +15,9 @@ node.createChildProcess = function (command) {
|
|||||||
return child;
|
return child;
|
||||||
};
|
};
|
||||||
|
|
||||||
node.exec = function (command) {
|
node.exec = function () {
|
||||||
var child = node.createChildProcess(command);
|
throw new Error("node.exec() has moved. Use include('/utils.js') to bring it back.");
|
||||||
var stdout = "";
|
}
|
||||||
var stderr = "";
|
|
||||||
var promise = new node.Promise();
|
|
||||||
|
|
||||||
child.addListener("output", function (chunk) {
|
|
||||||
if (chunk) stdout += chunk;
|
|
||||||
});
|
|
||||||
|
|
||||||
child.addListener("error", function (chunk) {
|
|
||||||
if (chunk) stderr += chunk;
|
|
||||||
});
|
|
||||||
|
|
||||||
child.addListener("exit", function (code) {
|
|
||||||
if (code == 0) {
|
|
||||||
promise.emitSuccess(stdout, stderr);
|
|
||||||
} else {
|
|
||||||
promise.emitError(code, stdout, stderr);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
node.tcp.createConnection = function (port, host) {
|
node.tcp.createConnection = function (port, host) {
|
||||||
var connection = new node.tcp.Connection();
|
var connection = new node.tcp.Connection();
|
||||||
@ -220,7 +199,6 @@ node.Module.prototype.loadObject = function (loadPromise) {
|
|||||||
node.dlopen(self.filename, self.target); // FIXME synchronus
|
node.dlopen(self.filename, self.target); // FIXME synchronus
|
||||||
loadPromise.emitSuccess(self.target);
|
loadPromise.emitSuccess(self.target);
|
||||||
} else {
|
} else {
|
||||||
node.error("Error reading " + self.filename + "\n");
|
|
||||||
loadPromise.emitError(new Error("Error reading " + self.filename));
|
loadPromise.emitError(new Error("Error reading " + self.filename));
|
||||||
node.exit(1);
|
node.exit(1);
|
||||||
}
|
}
|
||||||
|
54
src/util.js
54
src/util.js
@ -64,47 +64,23 @@ node.path = new function () {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
print = function (x) {
|
|
||||||
node.stdio.write(x);
|
|
||||||
};
|
|
||||||
|
|
||||||
puts = function (x) {
|
puts = function () {
|
||||||
print(x.toString() + "\n");
|
throw new Error("puts() has moved. Use include('/utils.js') to bring it back.");
|
||||||
};
|
}
|
||||||
|
|
||||||
node.debug = function (x) {
|
print = function () {
|
||||||
node.stdio.writeError("DEBUG: " + x.toString() + "\n");
|
throw new Error("print() has moved. Use include('/utils.js') to bring it back.");
|
||||||
};
|
}
|
||||||
|
|
||||||
node.error = function (x) {
|
p = function () {
|
||||||
node.stdio.writeError(x.toString() + "\n");
|
throw new Error("p() has moved. Use include('/utils.js') to bring it back.");
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
node.debug = function () {
|
||||||
* Echos the value of a value. Trys to print the value out
|
throw new Error("node.debug() has moved. Use include('/utils.js') to bring it back.");
|
||||||
* in the best way possible given the different types.
|
}
|
||||||
*
|
|
||||||
* @param {Object} value The object to print out
|
|
||||||
*/
|
|
||||||
node.inspect = function (value) {
|
|
||||||
if (value === 0) return "0";
|
|
||||||
if (value === false) return "false";
|
|
||||||
if (value === "") return '""';
|
|
||||||
if (typeof(value) == "function") return "[Function]";
|
|
||||||
if (value === undefined) return;
|
|
||||||
|
|
||||||
try {
|
node.error = function () {
|
||||||
return JSON.stringify(value);
|
throw new Error("node.error() has moved. Use include('/utils.js') to bring it back.");
|
||||||
} catch (e) {
|
}
|
||||||
// TODO make this recusrive and do a partial JSON output of object.
|
|
||||||
if (e.message.search("circular")) {
|
|
||||||
return "[Circular Object]";
|
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
p = function (x) {
|
|
||||||
node.error(node.inspect(x));
|
|
||||||
};
|
|
||||||
|
@ -5,6 +5,7 @@ exports.libDir = node.path.join(exports.testDir, "../../lib");
|
|||||||
node.libraryPaths.unshift(exports.libDir);
|
node.libraryPaths.unshift(exports.libDir);
|
||||||
|
|
||||||
var mjsunit = require("/mjsunit.js");
|
var mjsunit = require("/mjsunit.js");
|
||||||
|
include("/utils.js");
|
||||||
// Copy mjsunit namespace out
|
// Copy mjsunit namespace out
|
||||||
for (var prop in mjsunit) {
|
for (var prop in mjsunit) {
|
||||||
if (mjsunit.hasOwnProperty(prop)) exports[prop] = mjsunit[prop];
|
if (mjsunit.hasOwnProperty(prop)) exports[prop] = mjsunit[prop];
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
node.debug("load fixtures/a.js");
|
|
||||||
|
|
||||||
var c = require("b/c.js");
|
var c = require("b/c.js");
|
||||||
|
|
||||||
|
debug("load fixtures/a.js");
|
||||||
|
|
||||||
var string = "A";
|
var string = "A";
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
node.debug("load fixtures/b/c.js");
|
|
||||||
|
|
||||||
var d = require("d.js");
|
var d = require("d.js");
|
||||||
|
|
||||||
|
debug("load fixtures/b/c.js");
|
||||||
|
|
||||||
var string = "C";
|
var string = "C";
|
||||||
|
|
||||||
exports.C = function () {
|
exports.C = function () {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
node.debug("load fixtures/b/d.js");
|
debug("load fixtures/b/d.js");
|
||||||
|
|
||||||
var string = "D";
|
var string = "D";
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ setTimeout(function () {
|
|||||||
file.write("hello\n");
|
file.write("hello\n");
|
||||||
file.write("world\n");
|
file.write("world\n");
|
||||||
file.close().addCallback(function () {
|
file.close().addCallback(function () {
|
||||||
node.error("file closed...");
|
error("file closed...");
|
||||||
var out = node.fs.cat(testTxt).wait();
|
var out = node.fs.cat(testTxt).wait();
|
||||||
print("the file contains: ");
|
print("the file contains: ");
|
||||||
p(out);
|
p(out);
|
||||||
|
@ -3,7 +3,7 @@ include("common.js");
|
|||||||
success_count = 0;
|
success_count = 0;
|
||||||
error_count = 0;
|
error_count = 0;
|
||||||
|
|
||||||
node.exec("ls /").addCallback(function (out) {
|
exec("ls /").addCallback(function (out) {
|
||||||
success_count++;
|
success_count++;
|
||||||
p(out);
|
p(out);
|
||||||
}).addErrback(function (code, out, err) {
|
}).addErrback(function (code, out, err) {
|
||||||
@ -15,7 +15,7 @@ node.exec("ls /").addCallback(function (out) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
node.exec("ls /DOES_NOT_EXIST").addCallback(function (out) {
|
exec("ls /DOES_NOT_EXIST").addCallback(function (out) {
|
||||||
success_count++;
|
success_count++;
|
||||||
p(out);
|
p(out);
|
||||||
assertTrue(out != "");
|
assertTrue(out != "");
|
||||||
|
@ -5,8 +5,8 @@ var filename = node.path.join(fixturesDir, "does_not_exist.txt");
|
|||||||
var promise = node.fs.cat(filename, "raw");
|
var promise = node.fs.cat(filename, "raw");
|
||||||
|
|
||||||
promise.addCallback(function (content) {
|
promise.addCallback(function (content) {
|
||||||
node.debug("cat returned some content: " + content);
|
debug("cat returned some content: " + content);
|
||||||
node.debug("this shouldn't happen as the file doesn't exist...");
|
debug("this shouldn't happen as the file doesn't exist...");
|
||||||
assertTrue(false);
|
assertTrue(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4,17 +4,17 @@ var PROXY_PORT = 8869;
|
|||||||
var BACKEND_PORT = 8870;
|
var BACKEND_PORT = 8870;
|
||||||
|
|
||||||
var backend = node.http.createServer(function (req, res) {
|
var backend = node.http.createServer(function (req, res) {
|
||||||
// node.debug("backend");
|
// debug("backend");
|
||||||
res.sendHeader(200, {"content-type": "text/plain"});
|
res.sendHeader(200, {"content-type": "text/plain"});
|
||||||
res.sendBody("hello world\n");
|
res.sendBody("hello world\n");
|
||||||
res.finish();
|
res.finish();
|
||||||
});
|
});
|
||||||
// node.debug("listen backend")
|
// debug("listen backend")
|
||||||
backend.listen(BACKEND_PORT);
|
backend.listen(BACKEND_PORT);
|
||||||
|
|
||||||
var proxy_client = node.http.createClient(BACKEND_PORT);
|
var proxy_client = node.http.createClient(BACKEND_PORT);
|
||||||
var proxy = node.http.createServer(function (req, res) {
|
var proxy = node.http.createServer(function (req, res) {
|
||||||
node.debug("proxy req headers: " + JSON.stringify(req.headers));
|
debug("proxy req headers: " + JSON.stringify(req.headers));
|
||||||
var proxy_req = proxy_client.get(req.uri.path);
|
var proxy_req = proxy_client.get(req.uri.path);
|
||||||
proxy_req.finish(function(proxy_res) {
|
proxy_req.finish(function(proxy_res) {
|
||||||
res.sendHeader(proxy_res.statusCode, proxy_res.headers);
|
res.sendHeader(proxy_res.statusCode, proxy_res.headers);
|
||||||
@ -23,27 +23,27 @@ var proxy = node.http.createServer(function (req, res) {
|
|||||||
});
|
});
|
||||||
proxy_res.addListener("complete", function() {
|
proxy_res.addListener("complete", function() {
|
||||||
res.finish();
|
res.finish();
|
||||||
// node.debug("proxy res");
|
// debug("proxy res");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// node.debug("listen proxy")
|
// debug("listen proxy")
|
||||||
proxy.listen(PROXY_PORT);
|
proxy.listen(PROXY_PORT);
|
||||||
|
|
||||||
var body = "";
|
var body = "";
|
||||||
|
|
||||||
var client = node.http.createClient(PROXY_PORT);
|
var client = node.http.createClient(PROXY_PORT);
|
||||||
var req = client.get("/test");
|
var req = client.get("/test");
|
||||||
// node.debug("client req")
|
// debug("client req")
|
||||||
req.finish(function (res) {
|
req.finish(function (res) {
|
||||||
// node.debug("got res");
|
// debug("got res");
|
||||||
assertEquals(200, res.statusCode);
|
assertEquals(200, res.statusCode);
|
||||||
res.setBodyEncoding("utf8");
|
res.setBodyEncoding("utf8");
|
||||||
res.addListener("body", function (chunk) { body += chunk; });
|
res.addListener("body", function (chunk) { body += chunk; });
|
||||||
res.addListener("complete", function () {
|
res.addListener("complete", function () {
|
||||||
proxy.close();
|
proxy.close();
|
||||||
backend.close();
|
backend.close();
|
||||||
// node.debug("closed both");
|
// debug("closed both");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ req.finish(function (res) {
|
|||||||
responses_recvd += 1;
|
responses_recvd += 1;
|
||||||
res.setBodyEncoding("ascii");
|
res.setBodyEncoding("ascii");
|
||||||
res.addListener("body", function (chunk) { body0 += chunk; });
|
res.addListener("body", function (chunk) { body0 += chunk; });
|
||||||
node.debug("Got /hello response");
|
debug("Got /hello response");
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
@ -52,15 +52,15 @@ setTimeout(function () {
|
|||||||
responses_recvd += 1;
|
responses_recvd += 1;
|
||||||
res.setBodyEncoding("utf8");
|
res.setBodyEncoding("utf8");
|
||||||
res.addListener("body", function (chunk) { body1 += chunk; });
|
res.addListener("body", function (chunk) { body1 += chunk; });
|
||||||
node.debug("Got /world response");
|
debug("Got /world response");
|
||||||
});
|
});
|
||||||
}, 1);
|
}, 1);
|
||||||
|
|
||||||
process.addListener("exit", function () {
|
process.addListener("exit", function () {
|
||||||
node.debug("responses_recvd: " + responses_recvd);
|
debug("responses_recvd: " + responses_recvd);
|
||||||
assertEquals(2, responses_recvd);
|
assertEquals(2, responses_recvd);
|
||||||
|
|
||||||
node.debug("responses_sent: " + responses_sent);
|
debug("responses_sent: " + responses_sent);
|
||||||
assertEquals(2, responses_sent);
|
assertEquals(2, responses_sent);
|
||||||
|
|
||||||
assertEquals("The path was /hello", body0);
|
assertEquals("The path was /hello", body0);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
node.debug("load test-module-loading.js");
|
|
||||||
include("common.js");
|
include("common.js");
|
||||||
|
|
||||||
|
debug("load test-module-loading.js");
|
||||||
|
|
||||||
var a = require("fixtures/a.js");
|
var a = require("fixtures/a.js");
|
||||||
var d = require("fixtures/b/d.js");
|
var d = require("fixtures/b/d.js");
|
||||||
var d2 = require("fixtures/b/d.js");
|
var d2 = require("fixtures/b/d.js");
|
||||||
|
@ -44,7 +44,7 @@ var server = node.http.createServer(function(req, res) {
|
|||||||
server.listen(port);
|
server.listen(port);
|
||||||
|
|
||||||
var cmd = 'curl -H "Expect:" -F "test-field=foobar" -F test-file=@'+__filename+' http://localhost:'+port+'/';
|
var cmd = 'curl -H "Expect:" -F "test-field=foobar" -F test-file=@'+__filename+' http://localhost:'+port+'/';
|
||||||
var result = node.exec(cmd).wait();
|
var result = exec(cmd).wait();
|
||||||
|
|
||||||
process.addListener('exit', function() {
|
process.addListener('exit', function() {
|
||||||
assertEquals(2, parts_complete);
|
assertEquals(2, parts_complete);
|
||||||
|
@ -5,14 +5,14 @@ binaryString = "";
|
|||||||
for (var i = 255; i >= 0; i--) {
|
for (var i = 255; i >= 0; i--) {
|
||||||
var s = "'\\" + i.toString(8) + "'";
|
var s = "'\\" + i.toString(8) + "'";
|
||||||
S = eval(s);
|
S = eval(s);
|
||||||
node.error( s
|
error( s
|
||||||
+ " "
|
+ " "
|
||||||
+ JSON.stringify(S)
|
+ JSON.stringify(S)
|
||||||
+ " "
|
+ " "
|
||||||
+ JSON.stringify(String.fromCharCode(i))
|
+ JSON.stringify(String.fromCharCode(i))
|
||||||
+ " "
|
+ " "
|
||||||
+ S.charCodeAt(0)
|
+ S.charCodeAt(0)
|
||||||
);
|
);
|
||||||
node.assert(S.charCodeAt(0) == i);
|
node.assert(S.charCodeAt(0) == i);
|
||||||
node.assert(S == String.fromCharCode(i));
|
node.assert(S == String.fromCharCode(i));
|
||||||
binaryString += S;
|
binaryString += S;
|
||||||
@ -21,7 +21,7 @@ for (var i = 255; i >= 0; i--) {
|
|||||||
var echoServer = node.tcp.createServer(function (connection) {
|
var echoServer = node.tcp.createServer(function (connection) {
|
||||||
connection.setEncoding("binary");
|
connection.setEncoding("binary");
|
||||||
connection.addListener("receive", function (chunk) {
|
connection.addListener("receive", function (chunk) {
|
||||||
node.error("recved: " + JSON.stringify(chunk));
|
error("recved: " + JSON.stringify(chunk));
|
||||||
connection.send(chunk, "binary");
|
connection.send(chunk, "binary");
|
||||||
});
|
});
|
||||||
connection.addListener("eof", function () {
|
connection.addListener("eof", function () {
|
||||||
@ -38,7 +38,7 @@ var c = node.tcp.createConnection(PORT);
|
|||||||
c.setEncoding("binary");
|
c.setEncoding("binary");
|
||||||
c.addListener("receive", function (chunk) {
|
c.addListener("receive", function (chunk) {
|
||||||
if (j < 256) {
|
if (j < 256) {
|
||||||
node.error("send " + j);
|
error("send " + j);
|
||||||
c.send(String.fromCharCode(j), "binary");
|
c.send(String.fromCharCode(j), "binary");
|
||||||
j++;
|
j++;
|
||||||
} else {
|
} else {
|
||||||
|
@ -24,7 +24,7 @@ function pingPongTest (port, host, on_complete) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.addListener("timeout", function () {
|
socket.addListener("timeout", function () {
|
||||||
node.debug("server-side timeout!!");
|
debug("server-side timeout!!");
|
||||||
assertFalse(true);
|
assertFalse(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ function pingPongTest (port, host, on_complete) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.addListener("timeout", function () {
|
client.addListener("timeout", function () {
|
||||||
node.debug("client-side timeout!!");
|
debug("client-side timeout!!");
|
||||||
assertFalse(true);
|
assertFalse(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -63,5 +63,5 @@ client.addListener("eof", function () {
|
|||||||
|
|
||||||
process.addListener("exit", function () {
|
process.addListener("exit", function () {
|
||||||
assertEquals(N, recv.length);
|
assertEquals(N, recv.length);
|
||||||
node.debug("Exit");
|
debug("Exit");
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user