This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Add documentation about requiring system modules.

  • Loading branch information...
1 parent 106287c commit a3229ed7b7abff0b617db4a1b75121befc20c68b @ry ry committed Sep 23, 2009
Showing with 60 additions and 20 deletions.
  1. +21 −7 doc/api.html
  2. +24 −7 doc/api.txt
  3. +15 −6 doc/node.1
View
@@ -449,11 +449,6 @@ <h3 id="_modules">Modules</h3><div style="clear:left"></div>
<div class="paragraph"><p>The module path is relative to the file calling <tt>require()</tt>. That is,
<tt>circle.js</tt> must be in the same directory as <tt>foo.js</tt> for <tt>require()</tt> to
find it.</p></div>
-<div class="paragraph"><p>HTTP URLs can also be used to load modules. For example,</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>var circle = require("http://tinyclouds.org/node/circle.js");</tt></pre>
-</div></div>
<div class="paragraph"><p>Like <tt>require()</tt> the function <tt>include()</tt> also loads a module. Instead of
returning a namespace object, <tt>include()</tt> will add the module&#8217;s exports into
the global namespace. For example:</p></div>
@@ -462,7 +457,26 @@ <h3 id="_modules">Modules</h3><div style="clear:left"></div>
<pre><tt>include("circle.js");
puts("The area of a cirlce of radius 4 is " + area(4));</tt></pre>
</div></div>
-<div class="paragraph"><p>Functions <tt>require_async()</tt> and <tt>include_async()</tt> also exist.</p></div>
+<div class="paragraph"><p>When an absolute path is given to <tt>require()</tt> or <tt>include()</tt>, like
+<tt>require("/mjsunit.js")</tt> the module is searched for in the
+<tt>node.libraryPaths</tt> array. <tt>node.libraryPaths</tt> on my system looks like this:</p></div>
+<div class="listingblock">
+<div class="content">
+<pre><tt>[ "/home/ryan/.node_libraries"
+, "/home/ryan/local/node/lib/node_libraries"
+, "/"
+]</tt></pre>
+</div></div>
+<div class="paragraph"><p>That is, first Node looks for <tt>"/home/ryan/.node_libraries/mjsunit.js"</tt> and
+then for <tt>"/home/ryan/local/node/lib/node_libraries/mjsunit.js"</tt>. If not
+found, it finally looks for <tt>"/mjsunit.js"</tt> (in the root directory).</p></div>
+<div class="paragraph"><p><tt>node.libraryPaths</tt> can be modified at runtime by simply unshifting new
+paths on to it and at startup with the <tt>NODE_LIBRARY_PATHS</tt> environmental
+variable (which should be a list of paths, colon separated).</p></div>
+<div class="paragraph"><p>Node comes with several libraries which are installed when <tt>"make install"</tt>
+is run. These are currently undocumented, but do look them up in your
+system.</p></div>
+<div class="paragraph"><p>(Functions <tt>require_async()</tt> and <tt>include_async()</tt> also exist.)</p></div>
<h4 id="_tt_process_addlistener_exit_function_tt"><tt>process.addListener("exit", function () { })</tt></h4>
<div class="paragraph"><p>When the program exits a special object called <tt>process</tt> will emit an
<tt>"exit"</tt> event.</p></div>
@@ -1932,7 +1946,7 @@ <h2 id="_extension_api">Extension API</h2>
<div id="footer">
<div id="footer-text">
Version 0.1.11<br />
-Last updated 2009-09-23 15:35:53 CEST
+Last updated 2009-09-23 16:52:08 CEST
</div>
</div>
</body>
View
@@ -277,12 +277,6 @@ The module path is relative to the file calling +require()+. That is,
+circle.js+ must be in the same directory as +foo.js+ for +require()+ to
find it.
-HTTP URLs can also be used to load modules. For example,
-
-----------------------------------------
-var circle = require("http://tinyclouds.org/node/circle.js");
-----------------------------------------
-
Like +require()+ the function +include()+ also loads a module. Instead of
returning a namespace object, +include()+ will add the module's exports into
the global namespace. For example:
@@ -292,7 +286,30 @@ include("circle.js");
puts("The area of a cirlce of radius 4 is " + area(4));
----------------------------------------
-Functions +require_async()+ and +include_async()+ also exist.
+When an absolute path is given to +require()+ or +include()+, like
++require("/mjsunit.js")+ the module is searched for in the
++node.libraryPaths+ array. +node.libraryPaths+ on my system looks like this:
+
+----------------------------------------
+[ "/home/ryan/.node_libraries"
+, "/home/ryan/local/node/lib/node_libraries"
+, "/"
+]
+----------------------------------------
+
+That is, first Node looks for +"/home/ryan/.node_libraries/mjsunit.js"+ and
+then for +"/home/ryan/local/node/lib/node_libraries/mjsunit.js"+. If not
+found, it finally looks for +"/mjsunit.js"+ (in the root directory).
+
++node.libraryPaths+ can be modified at runtime by simply unshifting new
+paths on to it and at startup with the +NODE_LIBRARY_PATHS+ environmental
+variable (which should be a list of paths, colon separated).
+
+Node comes with several libraries which are installed when +"make install"+
+is run. These are currently undocumented, but do look them up in your
+system.
+
+(Functions +require_async()+ and +include_async()+ also exist.)
==== +process.addListener("exit", function () { })+
View
@@ -398,24 +398,33 @@ The module circle\.js has exported the functions area() and circumference()\. To
.sp
The module path is relative to the file calling require()\. That is, circle\.js must be in the same directory as foo\.js for require() to find it\.
.sp
-HTTP URLs can also be used to load modules\. For example,
+Like require() the function include() also loads a module\. Instead of returning a namespace object, include() will add the module\(cqs exports into the global namespace\. For example:
.sp
.sp
.RS 4
.nf
-var circle = require("http://tinyclouds\.org/node/circle\.js");
+include("circle\.js");
+puts("The area of a cirlce of radius 4 is " + area(4));
.fi
.RE
-Like require() the function include() also loads a module\. Instead of returning a namespace object, include() will add the module\(cqs exports into the global namespace\. For example:
+When an absolute path is given to require() or include(), like require("/mjsunit\.js") the module is searched for in the node\.libraryPaths array\. node\.libraryPaths on my system looks like this:
.sp
.sp
.RS 4
.nf
-include("circle\.js");
-puts("The area of a cirlce of radius 4 is " + area(4));
+[ "/home/ryan/\.node_libraries"
+, "/home/ryan/local/node/lib/node_libraries"
+, "/"
+]
.fi
.RE
-Functions require_async() and include_async() also exist\.
+That is, first Node looks for "/home/ryan/\.node_libraries/mjsunit\.js" and then for "/home/ryan/local/node/lib/node_libraries/mjsunit\.js"\. If not found, it finally looks for "/mjsunit\.js" (in the root directory)\.
+.sp
+node\.libraryPaths can be modified at runtime by simply unshifting new paths on to it and at startup with the NODE_LIBRARY_PATHS environmental variable (which should be a list of paths, colon separated)\.
+.sp
+Node comes with several libraries which are installed when "make install" is run\. These are currently undocumented, but do look them up in your system\.
+.sp
+(Functions require_async() and include_async() also exist\.)
.sp
.sp
.it 1 an-trap

0 comments on commit a3229ed

Please sign in to comment.