|
@ -6,7 +6,7 @@ Version, 0.1.26, 2010.01.20 |
|
|
|
|
|
|
|
|
== NAME |
|
|
== NAME |
|
|
|
|
|
|
|
|
node - evented I/O for V8 javascript |
|
|
node - evented I/O for V8 JavaScript |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -39,7 +39,7 @@ Server running at http://127.0.0.1:8000/ |
|
|
|
|
|
|
|
|
Node supports 3 string encodings. UTF-8 (+"utf8"+), ASCII (+"ascii"+), and |
|
|
Node supports 3 string encodings. UTF-8 (+"utf8"+), ASCII (+"ascii"+), and |
|
|
Binary (+"binary"+). +"ascii"+ and +"binary"+ only look at the first 8 bits |
|
|
Binary (+"binary"+). +"ascii"+ and +"binary"+ only look at the first 8 bits |
|
|
of the 16bit javascript string characters. Both are relatively fast--use |
|
|
of the 16bit JavaScript string characters. Both are relatively fast--use |
|
|
them if you can. +"utf8"+ is slower and should be avoided when possible. |
|
|
them if you can. +"utf8"+ is slower and should be avoided when possible. |
|
|
|
|
|
|
|
|
Unless otherwise noted, functions are all asynchronous and do not block |
|
|
Unless otherwise noted, functions are all asynchronous and do not block |
|
@ -64,6 +64,9 @@ The search path for absolute path arguments to +require()+. |
|
|
+__filename+ :: |
|
|
+__filename+ :: |
|
|
The filename of the script being executed. |
|
|
The filename of the script being executed. |
|
|
|
|
|
|
|
|
|
|
|
+__dirname+ :: |
|
|
|
|
|
The dirname of the script being executed. |
|
|
|
|
|
|
|
|
+module+ :: |
|
|
+module+ :: |
|
|
A reference to the current module (of type +process.Module+). In particular |
|
|
A reference to the current module (of type +process.Module+). In particular |
|
|
+module.exports+ is the same as the +exports+ object. See +src/process.js+ for |
|
|
+module.exports+ is the same as the +exports+ object. See +src/process.js+ for |
|
@ -79,7 +82,7 @@ more information. |
|
|
| +"exit"+ | +code+ | Made when the process exits. |
|
|
| +"exit"+ | +code+ | Made when the process exits. |
|
|
A listener on this event should not try to perform |
|
|
A listener on this event should not try to perform |
|
|
I/O since the process will forcibly exit in less |
|
|
I/O since the process will forcibly exit in less |
|
|
than microsecond. However, it is a good hook to |
|
|
than a microsecond. However, it is a good hook to |
|
|
perform constant time checks of the module's |
|
|
perform constant time checks of the module's |
|
|
state (like for unit tests). |
|
|
state (like for unit tests). |
|
|
+ |
|
|
+ |
|
@ -212,7 +215,7 @@ in a promise callback. |
|
|
---------------------------------------- |
|
|
---------------------------------------- |
|
|
var sys = require("sys"); |
|
|
var sys = require("sys"); |
|
|
sys.exec("ls /").addCallback(function (stdout, stderr) { |
|
|
sys.exec("ls /").addCallback(function (stdout, stderr) { |
|
|
puts(stdout); |
|
|
sys.puts(stdout); |
|
|
}); |
|
|
}); |
|
|
---------------------------------------- |
|
|
---------------------------------------- |
|
|
+ |
|
|
+ |
|
@ -239,7 +242,7 @@ complete. |
|
|
|
|
|
|
|
|
==== +events.EventEmitter+ |
|
|
==== +events.EventEmitter+ |
|
|
|
|
|
|
|
|
+require('events')+ to access the events module. |
|
|
+require("events")+ to access the events module. |
|
|
|
|
|
|
|
|
All EventEmitters emit the event +"newListener"+ when new listeners are |
|
|
All EventEmitters emit the event +"newListener"+ when new listeners are |
|
|
added. |
|
|
added. |
|
@ -258,7 +261,7 @@ Adds a listener to the end of the listeners array for the specified event. |
|
|
+ |
|
|
+ |
|
|
---------------------------------------- |
|
|
---------------------------------------- |
|
|
server.addListener("connection", function (socket) { |
|
|
server.addListener("connection", function (socket) { |
|
|
puts("someone connected!"); |
|
|
sys.puts("someone connected!"); |
|
|
}); |
|
|
}); |
|
|
---------------------------------------- |
|
|
---------------------------------------- |
|
|
|
|
|
|
|
@ -275,9 +278,9 @@ Execute each of the listeners in order with the supplied arguments. |
|
|
|
|
|
|
|
|
==== +events.Promise+ |
|
|
==== +events.Promise+ |
|
|
|
|
|
|
|
|
+require('events')+ to access the events module. |
|
|
+require("events")+ to access the events module. |
|
|
|
|
|
|
|
|
+events.Promise+ inherits from +process.eventEmitter+. A promise emits one of two |
|
|
+events.Promise+ inherits from +process.EventEmitter+. A promise emits one of two |
|
|
events: +"success"+ or +"error"+. After emitting its event, it will not |
|
|
events: +"success"+ or +"error"+. After emitting its event, it will not |
|
|
emit anymore events. |
|
|
emit anymore events. |
|
|
|
|
|
|
|
@ -304,7 +307,7 @@ If you created the promise (by doing +new events.Promise()+) then call |
|
|
the moment due to a bug; use +emitSuccess+ instead.) |
|
|
the moment due to a bug; use +emitSuccess+ instead.) |
|
|
|
|
|
|
|
|
+promise.emitError(arg1, arg2, ...)+ :: |
|
|
+promise.emitError(arg1, arg2, ...)+ :: |
|
|
Emits the +"error"+ event. If a no error handler is attached to the promise |
|
|
Emits the +"error"+ event. If no error handler is attached to the promise |
|
|
between +promise.emitError()+ and +process.nextTick()+, an exception is |
|
|
between +promise.emitError()+ and +process.nextTick()+, an exception is |
|
|
thrown. |
|
|
thrown. |
|
|
+ |
|
|
+ |
|
@ -348,10 +351,10 @@ setTimeout(function() { |
|
|
|
|
|
|
|
|
+promise.timeout(timeout = undefined)+ :: |
|
|
+promise.timeout(timeout = undefined)+ :: |
|
|
If the +timeout+ parameter is provided, the promise will emit an +"error"+ |
|
|
If the +timeout+ parameter is provided, the promise will emit an +"error"+ |
|
|
event after the given amount of millseconds. The timeout is canceled by any |
|
|
event after the given amount of milliseconds. The timeout is canceled by any |
|
|
+"success"+ or +"error"+ event being emitted by the Promise. |
|
|
+"success"+ or +"error"+ event being emitted by the promise. |
|
|
+ |
|
|
+ |
|
|
To tell apart a timeout from a regular "error" event, use the following test: |
|
|
To tell a timeout apart from a regular "error" event, use the following test: |
|
|
+ |
|
|
+ |
|
|
---------------------------------------- |
|
|
---------------------------------------- |
|
|
promise.addErrback(function(e) { |
|
|
promise.addErrback(function(e) { |
|
@ -422,7 +425,7 @@ Close stdin. |
|
|
|
|
|
|
|
|
=== Modules |
|
|
=== Modules |
|
|
|
|
|
|
|
|
Node uses the CommonJS module system |
|
|
Node uses the CommonJS module system. |
|
|
|
|
|
|
|
|
Node has a simple module loading system. In Node, files and modules are in |
|
|
Node has a simple module loading system. In Node, files and modules are in |
|
|
one-to-one correspondence. As an example, +foo.js+ loads the module |
|
|
one-to-one correspondence. As an example, +foo.js+ loads the module |
|
@ -495,14 +498,14 @@ Modules; see the section below about addons. +"index.js"+ allows one to |
|
|
package a module as a directory. |
|
|
package a module as a directory. |
|
|
|
|
|
|
|
|
+require.paths+ can be modified at runtime by simply unshifting new |
|
|
+require.paths+ can be modified at runtime by simply unshifting new |
|
|
paths on to it and at startup with the +NODE_PATH+ environmental |
|
|
paths onto it, or at startup with the +NODE_PATH+ environmental |
|
|
variable (which should be a list of paths, colon separated). |
|
|
variable (which should be a list of paths, colon separated). |
|
|
|
|
|
|
|
|
Use +process.mixin()+ to include modules into the global namespace. |
|
|
Use +process.mixin()+ to include modules into the global namespace. |
|
|
|
|
|
|
|
|
---------------------------------------- |
|
|
---------------------------------------- |
|
|
process.mixin(GLOBAL, require("./circle"), require("sys")); |
|
|
process.mixin(GLOBAL, require("./circle"), require("sys")); |
|
|
puts("The area of a cirlce of radius 4 is " + area(4)); |
|
|
puts("The area of a circle of radius 4 is " + area(4)); |
|
|
---------------------------------------- |
|
|
---------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -511,8 +514,8 @@ puts("The area of a cirlce of radius 4 is " + area(4)); |
|
|
=== Timers |
|
|
=== Timers |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+setTimeout(callback, delay)+:: |
|
|
+setTimeout(callback, delay, [arg, ...])+:: |
|
|
To schedule execution of callback after delay milliseconds. Returns a |
|
|
To schedule execution of +callback+ after +delay+ milliseconds. Returns a |
|
|
+timeoutId+ for possible use with +clearTimeout()+. |
|
|
+timeoutId+ for possible use with +clearTimeout()+. |
|
|
|
|
|
|
|
|
Optionally, you can also pass arguments to the callback. |
|
|
Optionally, you can also pass arguments to the callback. |
|
@ -522,8 +525,8 @@ Optionally, you can also pass arguments to the callback. |
|
|
Prevents said timeout from triggering. |
|
|
Prevents said timeout from triggering. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+setInterval(callback, delay)+:: |
|
|
+setInterval(callback, delay, [arg, ...])+:: |
|
|
To schedule the repeated execution of callback every +delay+ milliseconds. Returns |
|
|
To schedule the repeated execution of +callback+ every +delay+ milliseconds. Returns |
|
|
a +intervalId+ for possible use with +clearInterval()+. |
|
|
a +intervalId+ for possible use with +clearInterval()+. |
|
|
|
|
|
|
|
|
Optionally, you can also pass arguments to the callback. |
|
|
Optionally, you can also pass arguments to the callback. |
|
@ -547,7 +550,7 @@ Node provides a tridirectional +popen(3)+ facility through the class |
|
|
|
|
|
|
|
|
| +"output"+ | +data+ | Each time the child process |
|
|
| +"output"+ | +data+ | Each time the child process |
|
|
sends data to its +stdout+, this event is |
|
|
sends data to its +stdout+, this event is |
|
|
emitted. +data+ is a string. + If the child |
|
|
emitted. +data+ is a string. If the child |
|
|
process closes its +stdout+ stream (a common |
|
|
process closes its +stdout+ stream (a common |
|
|
thing to do on exit), this event will be emitted |
|
|
thing to do on exit), this event will be emitted |
|
|
with +data === null+. |
|
|
with +data === null+. |
|
@ -569,7 +572,7 @@ environmental variables. For example: |
|
|
---------------------------------------- |
|
|
---------------------------------------- |
|
|
var ls = process.createChildProcess("ls", ["-lh", "/usr"]); |
|
|
var ls = process.createChildProcess("ls", ["-lh", "/usr"]); |
|
|
ls.addListener("output", function (data) { |
|
|
ls.addListener("output", function (data) { |
|
|
puts(data); |
|
|
sys.puts(data); |
|
|
}); |
|
|
}); |
|
|
---------------------------------------- |
|
|
---------------------------------------- |
|
|
+ |
|
|
+ |
|
@ -651,16 +654,21 @@ sys.puts("stats: " + JSON.stringify(stats)); |
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+posix.stat(path)+ :: |
|
|
+posix.stat(path)+ :: |
|
|
See stat(2). |
|
|
See stat(2). |
|
|
- on success: Returns +posix.Stats+ object. It looks like this: |
|
|
- on success: Returns +posix.Stats+ object. It looks like this: |
|
|
+{ dev: 2049, ino: 305352, mode: 16877, nlink: 12, uid: 1000, gid: 1000, |
|
|
+ |
|
|
rdev: 0, size: 4096, blksize: 4096, blocks: 8, atime: |
|
|
------------------------------------------------------------------------------ |
|
|
"2009-06-29T11:11:55Z", mtime: "2009-06-29T11:11:40Z", ctime: |
|
|
{ dev: 2049, ino: 305352, mode: 16877, nlink: 12, uid: 1000, gid: 1000, |
|
|
"2009-06-29T11:11:40Z" }+ |
|
|
rdev: 0, size: 4096, blksize: 4096, blocks: 8, atime: |
|
|
See the +posix.Stats+ section below for more information. |
|
|
"2009-06-29T11:11:55Z", mtime: "2009-06-29T11:11:40Z", ctime: |
|
|
- on error: no parameters. |
|
|
"2009-06-29T11:11:40Z" }+ |
|
|
|
|
|
------------------------------------------------------------------------------ |
|
|
|
|
|
+ |
|
|
|
|
|
See the +posix.Stats+ section below for more information. |
|
|
|
|
|
|
|
|
|
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+posix.unlink(path)+ :: |
|
|
+posix.unlink(path)+ :: |
|
|
See unlink(2) |
|
|
See unlink(2) |
|
@ -673,11 +681,13 @@ sys.puts("stats: " + JSON.stringify(stats)); |
|
|
- on success: no parameters. |
|
|
- on success: no parameters. |
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+posix.mkdir(path, mode)+ :: |
|
|
+posix.mkdir(path, mode)+ :: |
|
|
See mkdir(2) |
|
|
See mkdir(2) |
|
|
- on success: no parameters. |
|
|
- on success: no parameters. |
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+posix.readdir(path)+ :: |
|
|
+posix.readdir(path)+ :: |
|
|
Reads the contents of a directory. |
|
|
Reads the contents of a directory. |
|
|
- on success: One argument, an array containing the names (strings) of the |
|
|
- on success: One argument, an array containing the names (strings) of the |
|
@ -706,25 +716,23 @@ sys.puts("stats: " + JSON.stringify(stats)); |
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
+posix.read(fd, length, position, encoding)+:: |
|
|
+posix.read(fd, length, position, encoding)+:: |
|
|
|
|
|
Read data from the file specified by +fd+. |
|
|
Read data from the file specified by +fd+. |
|
|
+ |
|
|
+ |
|
|
+length+ is an integer specifying the number of |
|
|
+length+ is an integer specifying the number of |
|
|
bytes to read. |
|
|
bytes to read. |
|
|
+ |
|
|
+ |
|
|
+position+ is an integer specifying where to begin |
|
|
+position+ is an integer specifying where to begin |
|
|
reading from in the file. |
|
|
reading from in the file. |
|
|
+ |
|
|
+ |
|
|
- on success: returns +data, bytes_read+, what was read from the file. |
|
|
- on success: returns +data, bytes_read+, what was read from the file. |
|
|
- on error: no parameters. |
|
|
- on error: no parameters. |
|
|
|
|
|
|
|
|
|
|
|
+posix.cat(filename, encoding="utf8")+:: |
|
|
+posix.cat(filename, encoding="utf8")+:: |
|
|
|
|
|
|
|
|
Outputs the entire contents of a file. Example: |
|
|
Outputs the entire contents of a file. Example: |
|
|
+ |
|
|
+ |
|
|
-------------------------------- |
|
|
-------------------------------- |
|
|
posix.cat("/etc/passwd").addCallback(function (content) { |
|
|
posix.cat("/etc/passwd").addCallback(function (content) { |
|
|
puts(content); |
|
|
sys.puts(content); |
|
|
}); |
|
|
}); |
|
|
-------------------------------- |
|
|
-------------------------------- |
|
|
+ |
|
|
+ |
|
@ -759,20 +767,22 @@ In particular, large, possibly chunk-encoded, messages. The interface is |
|
|
careful to never buffer entire requests or responses--the |
|
|
careful to never buffer entire requests or responses--the |
|
|
user is able to stream data. |
|
|
user is able to stream data. |
|
|
|
|
|
|
|
|
HTTP message headers are represented by an object like this |
|
|
HTTP message headers are represented by an object like this: |
|
|
|
|
|
|
|
|
---------------------------------------- |
|
|
---------------------------------------- |
|
|
{ "Content-Length": "123" |
|
|
{ "content-length": "123" |
|
|
, "Content-Type": "text/plain" |
|
|
, "content-type": "text/plain" |
|
|
, "Connection": "keep-alive" |
|
|
, "connection": "keep-alive" |
|
|
, "Accept": "*/*" |
|
|
, "accept": "*/*" |
|
|
} |
|
|
} |
|
|
---------------------------------------- |
|
|
---------------------------------------- |
|
|
|
|
|
|
|
|
In order to support the full spectrum of possible HTTP applications, Node"s |
|
|
Keys are lowercased. Values are not modified. |
|
|
|
|
|
|
|
|
|
|
|
In order to support the full spectrum of possible HTTP applications, Node's |
|
|
HTTP API is very low-level. It deals with connection handling and message |
|
|
HTTP API is very low-level. It deals with connection handling and message |
|
|
parsing only. It parses a message into headers and body but it does not |
|
|
parsing only. It parses a message into headers and body but it does not |
|
|
parse the actual headers or the body. |
|
|
parse the actual headers or the body. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
==== +http.Server+ |
|
|
==== +http.Server+ |
|
@ -799,12 +809,12 @@ parse the actual headers or the body. |
|
|
|
|
|
|
|
|
|========================================================= |
|
|
|========================================================= |
|
|
|
|
|
|
|
|
+http.createServer(request_listener, options);+ :: |
|
|
+http.createServer(request_listener, [options]);+ :: |
|
|
Returns a new web server object. |
|
|
Returns a new web server object. |
|
|
+ |
|
|
+ |
|
|
The +options+ argument is optional. The |
|
|
The +options+ argument is optional. The |
|
|
+options+ argument accepts the same values as the |
|
|
+options+ argument accepts the same values as the |
|
|
options argument for +tcp.Server+ does. |
|
|
options argument for +tcp.Server+. |
|
|
+ |
|
|
+ |
|
|
The +request_listener+ is a function which is automatically |
|
|
The +request_listener+ is a function which is automatically |
|
|
added to the +"request"+ event. |
|
|
added to the +"request"+ event. |
|
@ -812,12 +822,12 @@ added to the +"request"+ event. |
|
|
+server.setSecure(format_type, ca_certs, crl_list, private_key, certificate)+ :: |
|
|
+server.setSecure(format_type, ca_certs, crl_list, private_key, certificate)+ :: |
|
|
Enable TLS for all incoming connections, with the specified credentials. |
|
|
Enable TLS for all incoming connections, with the specified credentials. |
|
|
+ |
|
|
+ |
|
|
format_type currently has to be "X509_PEM", and each of the ca, crl, key and |
|
|
+format_type+ currently has to be "X509_PEM", and each of the ca, crl, key and |
|
|
cert parameters are in the format of PEM strings. |
|
|
cert parameters are in the format of PEM strings. |
|
|
+ |
|
|
+ |
|
|
The ca_certs is a string that holds a number of CA certificates for use in accepting |
|
|
+ca_certs+ is a string that holds a number of CA certificates for use in accepting |
|
|
client connections that authenticate themselves with a client certificate. |
|
|
client connections that authenticate themselves with a client certificate. |
|
|
The private_key is a PEM string of the unencrypted key for the server. |
|
|
+private_key+ is a PEM string of the unencrypted key for the server. |
|
|
|
|
|
|
|
|
+server.listen(port, hostname)+ :: |
|
|
+server.listen(port, hostname)+ :: |
|
|
Begin accepting connections on the specified port and hostname. |
|
|
Begin accepting connections on the specified port and hostname. |
|
@ -842,7 +852,7 @@ the user--and passed as the first argument to a +"request"+ listener. |
|
|
message body is received. Example: A chunk |
|
|
message body is received. Example: A chunk |
|
|
of the body is given as the single |
|
|
of the body is given as the single |
|
|
argument. The transfer-encoding has been |
|
|
argument. The transfer-encoding has been |
|
|
decoded. The body chunk is a String. The |
|
|
decoded. The body chunk is a string. The |
|
|
body encoding is set with |
|
|
body encoding is set with |
|
|
+request.setBodyEncoding()+. |
|
|
+request.setBodyEncoding()+. |
|
|
|
|
|
|
|
@ -858,7 +868,7 @@ The request method as a string. Read only. Example: |
|
|
|
|
|
|
|
|
+request.url+ :: |
|
|
+request.url+ :: |
|
|
Request URL string. This contains only the URL that is |
|
|
Request URL string. This contains only the URL that is |
|
|
present in the actual HTTP request. If the request is |
|
|
present in the actual HTTP request. If the request is: |
|
|
+ |
|
|
+ |
|
|
---------------------------------------- |
|
|
---------------------------------------- |
|
|
GET /status?name=ryan HTTP/1.1\r\n |
|
|
GET /status?name=ryan HTTP/1.1\r\n |
|
@ -866,7 +876,7 @@ Accept: text/plain\r\n |
|
|
\r\n |
|
|
\r\n |
|
|
---------------------------------------- |
|
|
---------------------------------------- |
|
|
+ |
|
|
+ |
|
|
Then +request.url+ will be |
|
|
Then +request.url+ will be: |
|
|
+ |
|
|
+ |
|
|
---------------------------------------- |
|
|
---------------------------------------- |
|
|
"/status?name=ryan" |
|
|
"/status?name=ryan" |
|
@ -912,7 +922,7 @@ The HTTP protocol version as a string. Read only. Examples: |
|
|
+"1.1"+, +"1.0"+ |
|
|
+"1.1"+, +"1.0"+ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+request.setBodyEncoding(encoding)+ :: |
|
|
+request.setBodyEncoding(encoding="binary")+ :: |
|
|
Set the encoding for the request body. Either +"utf8"+ or +"binary"+. Defaults |
|
|
Set the encoding for the request body. Either +"utf8"+ or +"binary"+. Defaults |
|
|
to +"binary"+. |
|
|
to +"binary"+. |
|
|
|
|
|
|
|
@ -937,7 +947,7 @@ passed as the second parameter to the +"request"+ event. |
|
|
+response.sendHeader(statusCode, headers)+ :: |
|
|
+response.sendHeader(statusCode, headers)+ :: |
|
|
|
|
|
|
|
|
Sends a response header to the request. The status code is a 3-digit HTTP |
|
|
Sends a response header to the request. The status code is a 3-digit HTTP |
|
|
status code, like +404+. The second argument, +headers+ are the response headers. |
|
|
status code, like +404+. The second argument, +headers+, are the response headers. |
|
|
+ |
|
|
+ |
|
|
Example: |
|
|
Example: |
|
|
+ |
|
|
+ |
|
@ -1036,11 +1046,11 @@ for the user to stream a body to the server with |
|
|
+client.setSecure(format_type, ca_certs, crl_list, private_key, certificate)+ :: |
|
|
+client.setSecure(format_type, ca_certs, crl_list, private_key, certificate)+ :: |
|
|
Enable TLS for the client connection, with the specified credentials. |
|
|
Enable TLS for the client connection, with the specified credentials. |
|
|
+ |
|
|
+ |
|
|
format_type currently has to be "X509_PEM", and each of the ca, crl, key and |
|
|
+format_type+ currently has to be "X509_PEM", and each of the ca, crl, key and |
|
|
cert parameters are in the format of PEM strings, and optional. |
|
|
cert parameters are in the format of PEM strings, and optional. |
|
|
+ |
|
|
+ |
|
|
The ca_certs is a string that holds a number of CA certificates for use in deciding the |
|
|
+ca_certs+ is a string that holds a number of CA certificates for use in deciding the |
|
|
authenticity of the remote server. The private_key is a PEM string of the unencrypted |
|
|
authenticity of the remote server. +private_key+ is a PEM string of the unencrypted |
|
|
key for the client, which together with the certificate allows the client to authenticate |
|
|
key for the client, which together with the certificate allows the client to authenticate |
|
|
itself to the server. |
|
|
itself to the server. |
|
|
|
|
|
|
|
@ -1095,7 +1105,7 @@ argument which is an instance of +http.ClientResponse+. |
|
|
+ |
|
|
+ |
|
|
In the +responseListener+ callback, one can add more listeners to the |
|
|
In the +responseListener+ callback, one can add more listeners to the |
|
|
response, in particular listening for the +"body"+ event. Note that |
|
|
response, in particular listening for the +"body"+ event. Note that |
|
|
the +responseListener+ is called before any part of the body is receieved, |
|
|
the +responseListener+ is called before any part of the body is received, |
|
|
so there is no need to worry about racing to catch the first part of the |
|
|
so there is no need to worry about racing to catch the first part of the |
|
|
body. As long as a listener for +"body"+ is added during the |
|
|
body. As long as a listener for +"body"+ is added during the |
|
|
+responseListener+ callback, the entire body will be caught. |
|
|
+responseListener+ callback, the entire body will be caught. |
|
@ -1104,7 +1114,7 @@ body. As long as a listener for +"body"+ is added during the |
|
|
// Good |
|
|
// Good |
|
|
request.finish(function (response) { |
|
|
request.finish(function (response) { |
|
|
response.addListener("body", function (chunk) { |
|
|
response.addListener("body", function (chunk) { |
|
|
puts("BODY: " + chunk); |
|
|
sys.puts("BODY: " + chunk); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -1112,7 +1122,7 @@ request.finish(function (response) { |
|
|
request.finish(function (response) { |
|
|
request.finish(function (response) { |
|
|
setTimeout(function () { |
|
|
setTimeout(function () { |
|
|
response.addListener("body", function (chunk) { |
|
|
response.addListener("body", function (chunk) { |
|
|
puts("BODY: " + chunk); |
|
|
sys.puts("BODY: " + chunk); |
|
|
}); |
|
|
}); |
|
|
}, 10); |
|
|
}, 10); |
|
|
}); |
|
|
}); |
|
@ -1241,7 +1251,7 @@ To use the TCP server and client one must +require("tcp")+. |
|
|
==== +tcp.Server+ |
|
|
==== +tcp.Server+ |
|
|
|
|
|
|
|
|
Here is an example of a echo server which listens for connections |
|
|
Here is an example of a echo server which listens for connections |
|
|
on port 7000 |
|
|
on port 7000: |
|
|
|
|
|
|
|
|
---------------------------------------- |
|
|
---------------------------------------- |
|
|
var tcp = require("tcp"); |
|
|
var tcp = require("tcp"); |
|
@ -1282,12 +1292,12 @@ the +"connection"+ event. |
|
|
+server.setSecure(format_type, ca_certs, crl_list, private_key, certificate)+ :: |
|
|
+server.setSecure(format_type, ca_certs, crl_list, private_key, certificate)+ :: |
|
|
Enable TLS for all incoming connections, with the specified credentials. |
|
|
Enable TLS for all incoming connections, with the specified credentials. |
|
|
+ |
|
|
+ |
|
|
format_type currently has to be "X509_PEM", and each of the ca, crl, key and |
|
|
+format_type+ currently has to be "X509_PEM", and each of the ca, crl, key and |
|
|
cert parameters are in the format of PEM strings. |
|
|
cert parameters are in the format of PEM strings. |
|
|
+ |
|
|
+ |
|
|
The ca_certs is a string that holds a number of CA certificates for use in accepting |
|
|
+ca_certs+ is a string that holds a number of CA certificates for use in accepting |
|
|
client connections that authenticate themselves with a client certificate. |
|
|
client connections that authenticate themselves with a client certificate. |
|
|
The private_key is a PEM string of the unencrypted key for the server. |
|
|
+private_key+ is a PEM string of the unencrypted key for the server. |
|
|
|
|
|
|
|
|
+server.listen(port, host=null, backlog=128)+ :: |
|
|
+server.listen(port, host=null, backlog=128)+ :: |
|
|
Tells the server to listen for TCP connections to +port+ and +host+. |
|
|
Tells the server to listen for TCP connections to +port+ and +host+. |
|
@ -1427,54 +1437,83 @@ in RFC2253. This function is synchronous. |
|
|
|
|
|
|
|
|
=== DNS module |
|
|
=== DNS module |
|
|
|
|
|
|
|
|
Use +require("dns")+ to access this module |
|
|
Use +require("dns")+ to access this module. |
|
|
|
|
|
|
|
|
Here is an example of which resolves +"www.google.com"+ then reverse |
|
|
Here is an example which resolves +"www.google.com"+ then reverse |
|
|
resolves the IP addresses which are returned. |
|
|
resolves the IP addresses which are returned. |
|
|
|
|
|
|
|
|
------------------------------------------------------------------------- |
|
|
------------------------------------------------------------------------- |
|
|
var dns = require("dns"); |
|
|
var dns = require("dns"), |
|
|
|
|
|
sys = require("sys"); |
|
|
|
|
|
|
|
|
var resolution = dns.resolve4("www.google.com"); |
|
|
var resolution = dns.resolve4("www.google.com"); |
|
|
|
|
|
|
|
|
resolution.addCallback(function (addresses, ttl, cname) { |
|
|
resolution.addCallback(function (addresses, ttl, cname) { |
|
|
puts("addresses: " + JSON.stringify(addresses)); |
|
|
sys.puts("addresses: " + JSON.stringify(addresses)); |
|
|
puts("ttl: " + JSON.stringify(ttl)); |
|
|
sys.puts("ttl: " + JSON.stringify(ttl)); |
|
|
puts("cname: " + JSON.stringify(cname)); |
|
|
sys.puts("cname: " + JSON.stringify(cname)); |
|
|
|
|
|
|
|
|
for (var i = 0; i < addresses.length; i++) { |
|
|
for (var i = 0; i < addresses.length; i++) { |
|
|
var a = addresses[i]; |
|
|
var a = addresses[i]; |
|
|
var reversing = dns.reverse(a); |
|
|
var reversing = dns.reverse(a); |
|
|
reversing.addCallback( function (domains, ttl, cname) { |
|
|
reversing.addCallback( function (domains, ttl, cname) { |
|
|
puts("reverse for " + a + ": " + JSON.stringify(domains)); |
|
|
sys.puts("reverse for " + a + ": " + JSON.stringify(domains)); |
|
|
}); |
|
|
}); |
|
|
reversing.addErrback( function (code, msg) { |
|
|
reversing.addErrback( function (code, msg) { |
|
|
puts("reverse for " + a + " failed: " + msg); |
|
|
sys.puts("reverse for " + a + " failed: " + msg); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
resolution.addErrback(function (code, msg) { |
|
|
resolution.addErrback(function (code, msg) { |
|
|
puts("error: " + msg); |
|
|
sys.puts("error: " + msg); |
|
|
}); |
|
|
}); |
|
|
------------------------------------------------------------------------- |
|
|
------------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
+dns.resolve(domain, rrtype = 'A')+:: |
|
|
|
|
|
|
|
|
+dns.resolve4(domain)+:: |
|
|
Resolves a domain (e.g. +"google.com"+) into an array of the record types |
|
|
|
|
|
specified by rrtype. Valid rrtypes are +A+ (IPV4 addresses), +AAAA+ (IPV6 |
|
|
Resolves a domain (e.g. +"google.com"+) into an array of IPv4 addresses (e.g. |
|
|
addresses), +MX+ (mail exchange records), +TXT+ (text records), +SRV+ |
|
|
+["74.125.79.104", "74.125.79.105", "74.125.79.106"]+). |
|
|
(SRV records), and +PTR+ (used for reverse IP lookups). |
|
|
This function returns a promise. |
|
|
This function returns a promise. |
|
|
- on success: returns +addresses, ttl, cname+. +ttl+ (time-to-live) is an integer |
|
|
- on success: returns +addresses, ttl, cname+. +ttl+ (time-to-live) is an integer |
|
|
specifying the number of seconds this result is valid for. +cname+ is the |
|
|
specifying the number of seconds this result is valid for. +cname+ is the |
|
|
canonical name for the query. |
|
|
canonical name for the query. |
|
|
|
|
|
The type of each item in +addresses+ is determined by the record type, and |
|
|
|
|
|
described in the documentation for the corresponding lookup methods below. |
|
|
- on error: returns +code, msg+. +code+ is one of the error codes listed |
|
|
- on error: returns +code, msg+. +code+ is one of the error codes listed |
|
|
below and +msg+ is a string describing the error in English. |
|
|
below and +msg+ is a string describing the error in English. |
|
|
|
|
|
|
|
|
|
|
|
+dns.resolve4(domain)+:: |
|
|
|
|
|
|
|
|
|
|
|
The same as +dns.resolve()+, but only for IPv4 queries (+A+ records). |
|
|
|
|
|
+addresses+ is an array of IPv4 addresses (e.g. +["74.125.79.104", |
|
|
|
|
|
"74.125.79.105", "74.125.79.106"]+). |
|
|
|
|
|
|
|
|
+dns.resolve6(domain)+:: |
|
|
+dns.resolve6(domain)+:: |
|
|
|
|
|
|
|
|
The same as +dns.resolve4()+ except for IPv6 queries (an +AAAA+ query). |
|
|
The same as +dns.resolve4()+ except for IPv6 queries (an +AAAA+ query). |
|
|
|
|
|
|
|
|
|
|
|
+dns.resolveMx(domain)+:: |
|
|
|
|
|
|
|
|
|
|
|
The same as +dns.resolve()+, but only for mail exchange queries (+MX+ records). |
|
|
|
|
|
+addresses+ is an array of MX records, each with a priority and an exchange |
|
|
|
|
|
attribute (e.g. +[{"priority": 10, "exchange": "mx.example.com"},...]+). |
|
|
|
|
|
|
|
|
|
|
|
+dns.resolveTxt(domain)+:: |
|
|
|
|
|
|
|
|
|
|
|
The same as +dns.resolve()+, but only for text queries (+TXT+ records). |
|
|
|
|
|
+addresses+ is an array of the text records available for +domain+ (e.g., |
|
|
|
|
|
+["v=spf1 ip4:0.0.0.0 ~all"]+). |
|
|
|
|
|
|
|
|
|
|
|
+dns.resolveSrv(domain)+:: |
|
|
|
|
|
|
|
|
|
|
|
The same as +dns.resolve()+, but only for service records (+SRV+ records). |
|
|
|
|
|
+addresses+ is an array of the SRV records available for +domain+. Properties |
|
|
|
|
|
of SRV records are priority, weight, port, and name (e.g., +[{"priority": 10, |
|
|
|
|
|
{"weight": 5, "port": 21223, "name": "service.example.com"}, ...]+). |
|
|
|
|
|
|
|
|
+dns.reverse(ip)+:: |
|
|
+dns.reverse(ip)+:: |
|
|
|
|
|
|
|
|
Reverse resolves an ip address to an array of domain names. |
|
|
Reverse resolves an ip address to an array of domain names. |
|
@ -1518,10 +1557,10 @@ Tests for deep equality. |
|
|
Tests for any deep inequality. |
|
|
Tests for any deep inequality. |
|
|
|
|
|
|
|
|
+assert.strictEqual(actual, expected, message)+:: |
|
|
+assert.strictEqual(actual, expected, message)+:: |
|
|
Tests strict equality, as determined by bitwise equality operator ( +===+ ) |
|
|
Tests strict equality, as determined by the strict equality operator ( +===+ ) |
|
|
|
|
|
|
|
|
+assert.notStrictEqual(actual, expected, message)+:: |
|
|
+assert.notStrictEqual(actual, expected, message)+:: |
|
|
Tests strict non-equality, as determined by bitwise not equal operator ( +!==+ ) |
|
|
Tests strict non-equality, as determined by the strict not equal operator ( +!==+ ) |
|
|
|
|
|
|
|
|
+assert.throws(block, error, message)+:: |
|
|
+assert.throws(block, error, message)+:: |
|
|
Expects +block+ to throw an error. |
|
|
Expects +block+ to throw an error. |
|
@ -1533,7 +1572,7 @@ Expects +block+ not to throw an error. |
|
|
=== Path Module |
|
|
=== Path Module |
|
|
|
|
|
|
|
|
This module contains utilities for dealing with file paths. Use |
|
|
This module contains utilities for dealing with file paths. Use |
|
|
+require('path')+ to use it. It provides the following methods: |
|
|
+require("path")+ to use it. It provides the following methods: |
|
|
|
|
|
|
|
|
+path.join(/* path1, path2, ... */)+:: |
|
|
+path.join(/* path1, path2, ... */)+:: |
|
|
Join all arguments together and resolve the resulting path. Example: |
|
|
Join all arguments together and resolve the resulting path. Example: |
|
@ -1581,9 +1620,9 @@ node> require("path").dirname("/foo/bar/baz/asdf/quux") |
|
|
Return the last portion of a path. Similar to the Unix +basename+ command. Example: |
|
|
Return the last portion of a path. Similar to the Unix +basename+ command. Example: |
|
|
+ |
|
|
+ |
|
|
------------------------------------ |
|
|
------------------------------------ |
|
|
node> require("path").filename("/foo/bar/baz/asdf/quux.html") |
|
|
node> require("path").basename("/foo/bar/baz/asdf/quux.html") |
|
|
"quux.html" |
|
|
"quux.html" |
|
|
node> require("path").filename("/foo/bar/baz/asdf/quux.html", ".html") |
|
|
node> require("path").basename("/foo/bar/baz/asdf/quux.html", ".html") |
|
|
"quux" |
|
|
"quux" |
|
|
------------------------------------ |
|
|
------------------------------------ |
|
|
+ |
|
|
+ |
|
@ -1650,7 +1689,7 @@ Either the "params" portion of the query string, or a querystring-parsed object. |
|
|
+"query=string"+ or +{"query":"string"}+ |
|
|
+"query=string"+ or +{"query":"string"}+ |
|
|
|
|
|
|
|
|
+hash+:: |
|
|
+hash+:: |
|
|
The portion of the URL after the pound-sign. Example: +"#hash"+ |
|
|
The "fragment" portion of the URL including the pound-sign. Example: +"#hash"+ |
|
|
|
|
|
|
|
|
The following methods are provided by the URL module: |
|
|
The following methods are provided by the URL module: |
|
|
|
|
|
|
|
@ -1697,10 +1736,10 @@ node> require("querystring").parse("foo=bar&baz%5Bquux%5D=asdf&baz%5Boof%5D=rab& |
|
|
------------------------------------ |
|
|
------------------------------------ |
|
|
+ |
|
|
+ |
|
|
|
|
|
|
|
|
+querystring.escape+ |
|
|
+querystring.escape+:: |
|
|
The escape function used by +querystring.stringify+, provided so that it could be overridden if necessary. |
|
|
The escape function used by +querystring.stringify+, provided so that it could be overridden if necessary. |
|
|
|
|
|
|
|
|
+querystring.unescape+ |
|
|
+querystring.unescape+:: |
|
|
The unescape function used by +querystring.parse+, provided so that it could be overridden if necessary. |
|
|
The unescape function used by +querystring.parse+, provided so that it could be overridden if necessary. |
|
|
|
|
|
|
|
|
== REPL |
|
|
== REPL |
|
@ -1746,7 +1785,7 @@ Addons are dynamically linked shared objects. They can provide glue to C and |
|
|
C++ libraries. The API (at the moment) is rather complex, involving |
|
|
C++ libraries. The API (at the moment) is rather complex, involving |
|
|
knowledge of several libraries: |
|
|
knowledge of several libraries: |
|
|
|
|
|
|
|
|
- V8 Javascript, a C++ library. Used for interfacing with Javascript: |
|
|
- V8 JavaScript, a C++ library. Used for interfacing with JavaScript: |
|
|
creating objects, calling functions, etc. Documented mostly in the |
|
|
creating objects, calling functions, etc. Documented mostly in the |
|
|
+v8.h+ header file (+deps/v8/include/v8.h+ in the Node source tree). |
|
|
+v8.h+ header file (+deps/v8/include/v8.h+ in the Node source tree). |
|
|
|
|
|
|
|
|