Permalink
Browse files

API: Move node.puts(), node.exec() and others to /utils.js

  • Loading branch information...
1 parent c35dfdf commit 7abad8b7b360bc328243475fa59b899fcb902c60 @ry ry committed Sep 28, 2009
View
@@ -36,7 +36,8 @@ <h2 id="_synopsis">SYNOPSIS</h2>
World":</p></div>
<div class="listingblock">
<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.sendBody("Hello World\n");
response.finish();
@@ -59,124 +60,122 @@ <h2 id="_api">API</h2>
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
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>
<dt class="hdlist1">
-<tt>puts(string)</tt>
+<tt>node.exit(code)</tt>
</dt>
<dd>
<p>
-Outputs the <tt>string</tt> and a trailing new-line to <tt>stdout</tt>.
+Immediately ends the process with the specified code.
</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>
+<tt>node.cwd()</tt>
</dt>
<dd>
<p>
-A synchronous output function. Will block the process and
-output the string immediately to stdout.
+Returns the current working directory of the process.
</p>
</dd>
<dt class="hdlist1">
-<tt>node.inspect(object)</tt>
+<tt>ARGV</tt>
</dt>
<dd>
<p>
-Return a string representation of the <tt>object</tt>. (For debugging.)
+An array containing the command line arguments.
</p>
</dd>
<dt class="hdlist1">
-<tt>print(string)</tt>
+<tt>ENV</tt>
</dt>
<dd>
<p>
-Like <tt>puts()</tt> but without the trailing new-line.
+An object containing the user environment. See environ(7).
</p>
</dd>
<dt class="hdlist1">
-<tt>node.exit(code)</tt>
+<tt>__filename</tt>
</dt>
<dd>
<p>
-Immediately ends the process with the specified code.
+The filename of the script being executed.
</p>
</dd>
<dt class="hdlist1">
-<tt>node.exec(command)</tt>
+<tt>process</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
+A special global object. The <tt>process</tt> object is like the <tt>window</tt> object of
+browser-side javascript.
</p>
-</li>
-</ul></div>
</dd>
+</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>node.cwd()</tt>
+<tt>puts(string)</tt>
</dt>
<dd>
<p>
-Returns the current working directory of the process.
+Outputs the <tt>string</tt> and a trailing new-line to <tt>stdout</tt>.
</p>
</dd>
-</dl></div>
-<h3 id="_global_variables">Global Variables</h3><div style="clear:left"></div>
-<div class="dlist"><dl>
<dt class="hdlist1">
-<tt>ARGV</tt>
+<tt>print(string)</tt>
</dt>
<dd>
<p>
-An array containing the command line arguments.
+Like <tt>puts()</tt> but without the trailing new-line.
</p>
</dd>
<dt class="hdlist1">
-<tt>ENV</tt>
+<tt>debug(string)</tt>
</dt>
<dd>
<p>
-An object containing the user environment. See environ(7).
+A synchronous output function. Will block the process and
+output the string immediately to stdout.
</p>
</dd>
<dt class="hdlist1">
-<tt>__filename</tt>
+<tt>inspect(object)</tt>
</dt>
<dd>
<p>
-The filename of the script being executed.
+Return a string representation of the <tt>object</tt>. (For debugging.)
</p>
</dd>
<dt class="hdlist1">
-<tt>process</tt>
+<tt>exec(command)</tt>
</dt>
<dd>
<p>
-A special global object. The <tt>process</tt> object is like the <tt>window</tt> object of
-browser-side javascript.
+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>
@@ -1944,7 +1943,7 @@ <h2 id="_extension_api">Extension API</h2>
<div id="footer">
<div id="footer-text">
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>
</body>
View
@@ -16,6 +16,7 @@ An example of a web server written with Node which responds with "Hello
World":
----------------------------------------
+include("/utils.js");
node.http.createServer(function (request, response) {
response.sendHeader(200, {"Content-Type": "text/plain"});
response.sendBody("Hello World\n");
@@ -45,40 +46,55 @@ Unless otherwise noted, functions are all asynchronous and do not block
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.
+These objects are available to all programs.
++node.exit(code)+::
+Immediately ends the process with the specified code.
-+node.debug(string)+::
-A synchronous output function. Will block the process and
-output the string immediately to stdout.
++node.cwd()+::
+Returns the current working directory of the process.
++ARGV+ ::
+An array containing the command line arguments.
-+node.inspect(object)+ ::
-Return a string representation of the +object+. (For debugging.)
++ENV+ ::
+An object containing the user environment. See environ(7).
+
++__filename+ ::
+The filename of the script being executed.
++process+ ::
+A special global object. The +process+ object is like the +window+ object of
+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.
-+node.exit(code)+::
-Immediately ends the process with the specified code.
++inspect(object)+ ::
+Return a string representation of the +object+. (For debugging.)
-+node.exec(command)+::
++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) {
+include("/utils.js");
+exec("ls /").addCallback(function (stdout, stderr) {
puts(stdout);
});
----------------------------------------
@@ -87,27 +103,6 @@ node.exec("ls /").addCallback(function (stdout, stderr) {
- on error: exit code, stdout buffer, stderr buffer
-+node.cwd()+::
-Returns the current working directory of the process.
-
-
-=== Global Variables
-
-
-
-+ARGV+ ::
-An array containing the command line arguments.
-
-+ENV+ ::
-An object containing the user environment. See environ(7).
-
-+__filename+ ::
-The filename of the script being executed.
-
-+process+ ::
-A special global object. The +process+ object is like the +window+ object of
-browser-side javascript.
-
=== Events
Oops, something went wrong.

0 comments on commit 7abad8b

Please sign in to comment.