World":
----------------------------------------
-node.mixin(require("/utils.js"));
-node.mixin(require("/http.js"));
-createServer(function (request, response) {
+var sys = require("/sys.js"),
+ http = require("/http.js");
+http.createServer(function (request, response) {
response.sendHeader(200, {"Content-Type": "text/plain"});
response.sendBody("Hello World\n");
response.finish();
}).listen(8000);
-puts("Server running at http://127.0.0.1:8000/");
+sys.puts("Server running at http://127.0.0.1:8000/");
----------------------------------------
To run the server, put the code into a file called +example.js+ and execute
An object containing the user environment. See environ(7).
-=== Utilities
+=== System module
-These function are in +"/utils.js"+. Use +require("/utils.js")+ to access them.
+These function are in +"/sys.js"+. Use +require("/sys.js")+ to access them.
+puts(string)+::
Outputs the +string+ and a trailing new-line to +stdout+.
in a promise callback.
+
----------------------------------------
-node.mixin(require("/utils.js"));
-exec("ls /").addCallback(function (stdout, stderr) {
+var sys = require("/sys.js");
+sys.exec("ls /").addCallback(function (stdout, stderr) {
puts(stdout);
});
----------------------------------------
The contents of +foo.js+:
----------------------------------------
-var circle = require("circle.js");
-node.mixin(require("/utils.js"));
-puts("The area of a circle of radius 4 is " + circle.area(4));
+var circle = require("circle.js"),
+ sys = require("/sys.js");
+sys.puts("The area of a circle of radius 4 is " + circle.area(4));
----------------------------------------
The contents of +circle.js+:
object. (Alternatively, one can use +this+ instead of +exports+.) Variables
local to the module will be private. In this example the variable +PI+ is
private to +circle.js+. The function +puts()+ comes from the module
-+"/utils.js"+.
++"/sys.js"+.
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
Use +node.mixin()+ to include modules into the global namespace.
----------------------------------------
-node.mixin(process, require("circle.js"), require("/utils.js"));
+node.mixin(process, require("circle.js"), require("/sys.js"));
puts("The area of a cirlce of radius 4 is " + area(4));
----------------------------------------
----------------------------------------
+
Note, if you just want to buffer the output of a command and return it, then
-+exec()+ in +/utils.js+ might be better.
++exec()+ in +/sys.js+ might be better.
+child.pid+ ::
on port 7000
----------------------------------------
-node.mixin(require("/tcp.js"));
-var server = createServer(function (socket) {
+var tcp = require("/tcp.js");
+var server = tcp.createServer(function (socket) {
socket.setEncoding("utf8");
socket.addListener("connect", function () {
socket.send("hello\r\n");
The library is called +/repl.js+ and it can be used like this:
------------------------------------
-node.mixin(require("/utils.js"));
-node.mixin(require("/tcp.js"));
+var sys = require("/sys.js"),
+ tcp = require("/tcp.js"),
+ repl = require("/repl.js");
nconnections = 0;
-createServer(function (c) {
- error("Connection!");
+tcp.createServer(function (c) {
+ sys.error("Connection!");
nconnections += 1;
c.close();
}).listen(5000);
-require("/repl.js").start("simple tcp server> ");
+repl.start("simple tcp server> ");
------------------------------------