diff --git a/node.html b/website/node.html similarity index 54% rename from node.html rename to website/node.html index 7e8d6ff34c..4c9ff9d7b0 100644 --- a/node.html +++ b/website/node.html @@ -30,54 +30,28 @@ body { } #toc a { color: #777; } -h1, h2, h3, h4 { color: #bbb; } - -h1 { - margin: 2em 0; - padding: 0px 0px 0px 0px; - font-size: 51px; - line-height: 44px; - font-weight: bold; -} -h1 a { color: inherit; } - -h2 { - font-size: 30px; - line-height: inherit; - font-weight: bold; - margin: 2em 0; +h1, h2, h3, h4 { + margin: 2em 0; } -h3 { - margin: 2em 0; - font-size: 20px; - line-height: inherit; - font-weight: bold; -} +h1 a { color: inherit; } -h4 { - margin: 1em 0; - font-size: inherit; - line-height: inherit; - font-weight: bold; -} pre, code { font-family: monospace; font-size: 13pt; - color: #aaf; + color: #bab; } pre { - padding-left: 2em; + padding-left: 1em; + border-left: 1px solid #444; } dl { } dt { - color: #aaf; - font-weight: bold; } dd { @@ -93,9 +67,13 @@ a:hover { text-decoration: underline; } padding: 0.2em 0; } - + + + + + node.js - +
  1. Motivation
  2. @@ -124,22 +102,17 @@ a:hover { text-decoration: underline; }

    Node is a purely asynchronous I/O framework for V8 javascript. -

    This is an example of a web server written with Node which responds with -"Hello World" after waiting two seconds: -

    -new node.http.Server(function (msg) {
    +

    This is an example of a web server written with Node which listens on +port 8000 and responds with "Hello World" after waiting two seconds: +

    new node.http.Server(function (req, res) {
       setTimeout(function () {
    -    msg.sendHeader(200, [["Content-Type", "text/plain"]]);
    -    msg.sendBody("Hello World");
    -    msg.finish();
    +    res.sendHeader(200, [["Content-Type", "text/plain"]]);
    +    res.sendBody("Hello World");
    +    res.finish();
       }, 2000);
    -}).listen(8000, "localhost");
    +}).listen(8000);
     
    -

    This script can handle hundreds of concurrent requests while using -little CPU or memory—see benchmarks. - -

    Check out the API documentation for more examples. @@ -225,54 +198,62 @@ l2 cache ~ 14

    Build

    -
    configure
    +
    ./configure
     make
     make install

    Application Programming Interface

    -

    The node executable should be given an argument pointing to a -javascript file. +

    Conventions: Callbacks are object members which are prefixed with +on. All methods and members are camel cased. Constructors +always have a capital first letter.

    Timers

    -

    The timer API is the same as in the browser. The functions -setTimeout, setInterval, clearTimeout, and clearInterval +

    Timers allow one to schedule execution of a function for a later time. + +

    Timers in Node work as they do in the browser: +setTimeout, +setInterval, +clearTimeout, +clearInterval. +See Mozilla's + documentation for more information.

    File System

    TCP

    -

    HTTP (node.http)

    +

    HTTP (node.http)

    -

    Node provides a fast web server and client interface. The interface is -rather low-level. Node, for example, will not parse -application/x-www-form-urlencoded message bodies—that is -for higher level code to manage. The interface does abstract the -Transfer-Encoding (i.e. chuncked or identity), Message boundarys, and -Keep-Alive connections. +

    Node provides a web server and client interface. The interface is rather +low-level but complete. For example, it does not parse +application/x-www-form-urlencoded message bodies. The interface +does abstract the Transfer-Encoding (i.e. chuncked or identity), Message +boundarys, and Keep-Alive connections. -

    HTTP Server (node.http.Server)

    +

    HTTP Server (node.http.Server)

    -
    new Server(request_handler, options)
    +
    new Server(request_handler, options)
    -

    Creates a new web server. The options argument accepts +

    Creates a new web server. The options argument accepts the same values as the options argument for - node.tcp.Server does. The options argument is optional. + node.tcp.Server does. The options argument is optional. -

    The request_handler is a function which is called on - each request with a Message object argument. +

    The request_handler is a function which is called on + each request with a Message object argument.

    -
    server.listen(port, hostname) +
    server.listen(port, hostname)

    Begin accepting connections on the specified port and hostname. If the hostname is omitted, the server will accept connections directed to any address.

    -
    server.close() +
    server.close()

    Stops the server. Requests currently in progress will not be interrupted. @@ -280,23 +261,29 @@ Keep-Alive connections.

    -

    HTTP Request Message (node.http.Message)

    +

    HTTP Request Message (node.http.Message)

    This object is only created internally—not by the user. It is passed -as an argument to the request_handler function in a web server. +as an argument to the request_handler callback in a web server. + +

    This object, unlike in other HTTP APIs, is used as an interface for both +the request and response. Members and callbacks reference request data, like +msg.method and msg.onBody. The methods are for +sending a response to this message. Like msg.sendHeader() and +msg.sendBody().

    -
    msg.method -
    The request method as a string. Read only. Example: "GET", - "DELETE".
    +
    msg.method +
    The request method as a string. Read only. Example: "GET", + "DELETE".
    -
    msg.uri +
    msg.uri
    The request URI as a string. Read only. - Example: "/index.html?hello=world".
    + Example: "/index.html?hello=world". -
    msg.headers +
    msg.headers
    The request headers expressed as an array of 2-element arrays. Read only. Example: -
    +
     [ ["Content-Length", "123"]
     , ["Content-Type", "text/plain"]
     , ["Connection", "keep-alive"]
    @@ -304,19 +291,19 @@ as an argument to the request_handler function in a web server.
     ]
     
    -
    msg.http_version
    -
    The HTTP protocol version as a string. Read only. Examples: "1.1", - "1.0" +
    msg.http_version
    +
    The HTTP protocol version as a string. Read only. Examples: "1.1", + "1.0" -
    msg.connection
    -
    A reference to the node.tcp.Connection object. Read +
    msg.connection
    +
    A reference to the node.tcp.Connection object. Read only. Note that multiple messages can be sent on a single connection.
    -
    msg.onBody
    +
    msg.onBody
    Callback. Should be set by the user to be informed of when a piece of the message body is received. Example: -
    +
     msg.onBody = function (chunk) {
       puts("part of the body: " + chunk);
     }
    @@ -326,26 +313,26 @@ msg.onBody = function (chunk) {
       

    The body chunk is either a String in the case of utf8 encoding or an array of numbers in the case of raw encoding. -

    msg.onBodyComplete
    +
    msg.onBodyComplete
    Callback. Made exactly once for each message. No arguments. After - onBodyComplete is executed onBody will no longer be called. + onBodyComplete is executed onBody will no longer be called.
    -
    msg.setBodyEncoding(encoding)
    +
    msg.setBodyEncoding(encoding)
    - Set the encoding for the request body. Either "utf8" or - "raw". Defaults to raw. + Set the encoding for the request body. Either "utf8" or + "raw". Defaults to raw. TODO -
    msg.sendHeader(status_code, headers)
    +
    msg.sendHeader(status_code, headers)
    Sends a response header to the request. The status code is a 3-digit - HTTP status code, like 404. The second argument, - headers, should be an array of 2-element arrays, + HTTP status code, like 404. The second argument, + headers, should be an array of 2-element arrays, representing the response headers.

    Example: -

    +
     var body = "hello world";
     msg.sendHeader( 200
                   , [ ["Content-Length", body.length] 
    @@ -354,21 +341,21 @@ msg.sendHeader( 200
                   );
     
    This method must only be called once on a message and it must be called - before msg.finish() is called. + before msg.finish() is called.
    -
    msg.sendBody(chunk)
    +
    msg.sendBody(chunk)
    - This method must be called after sendHeader was called. It + This method must be called after sendHeader was called. It sends a chunk of the response body. This method may be called multiple times to provide successive parts of the body.
    -
    msg.finish()
    +
    msg.finish()
    This method signals that all of the response headers and body has been sent; that server should consider this message complete. - The method, msg.finish(), MUST be called on each response. + The method, msg.finish(), MUST be called on each response.
    @@ -378,19 +365,19 @@ msg.sendHeader( 200 in one-to-one correspondence.

    As an example, -foo.js loads the module mjsunit.js. +foo.js loads the module mjsunit.js. -

    The contents of foo.js: +

    The contents of foo.js: -

    +
     include("mjsunit");
     function onLoad () {
       assertEquals(1, 2);
     }
     
    -

    The contents of mjsunit.js: +

    The contents of mjsunit.js: -

    +
     function fail (expected, found, name_opt) {
       // ...
     }
    @@ -404,33 +391,33 @@ function deepEquals (a, b) {
     };
     
    -

    Here the module mjsunit.js has exported the function -assertEquals(). mjsunit.js must be in the -same directory as foo.js for include() to find it. -The module path is relative to the file calling include(). -The module path does not include filename extensions like .js. +

    Here the module mjsunit.js has exported the function +assertEquals(). mjsunit.js must be in the +same directory as foo.js for include() to find it. +The module path is relative to the file calling include(). +The module path does not include filename extensions like .js. -

    include() inserts the exported objects +

    include() inserts the exported objects from the specified module into the global namespace.

    Because file loading does not happen instantaneously, and because Node -has a policy of never blocking, the callback onLoad() is +has a policy of never blocking, the callback onLoad() is provided to notify the user when all the included modules are loaded. -Each file can have its own onLoad() callback. -onLoad() will always be called exactly once for each file. +Each file can have its own onLoad() callback. +onLoad() will always be called exactly once for each file.

    To export an object, add to the special exports object. -

    The functions fail and deepEquals are not +

    The functions fail and deepEquals are not exported and remain private to the module. -

    In addition to include() a module can use -require(). Instead of loading the exported objects into the +

    In addition to include() a module can use +require(). Instead of loading the exported objects into the global namespace, it will return a namespace object. The exported objects -can only be guaranteed to exist after the onLoad() callback is +can only be guaranteed to exist after the onLoad() callback is made. For example: -

    +
     var mjsunit = require("mjsunit");
     
     function onLoad () {
    @@ -438,8 +425,8 @@ function onLoad () {
     }
     
    -

    include() and require() cannot be used after -onLoad() is called. So put them at the beginning of your file. +

    include() and require() cannot be used after +onLoad() is called. So put them at the beginning of your file. diff --git a/website/sh_javascript.min.js b/website/sh_javascript.min.js new file mode 100644 index 0000000000..d12482ced2 --- /dev/null +++ b/website/sh_javascript.min.js @@ -0,0 +1 @@ +if(!this.sh_languages){this.sh_languages={}}sh_languages.javascript=[[[/\/\/\//g,"sh_comment",1],[/\/\//g,"sh_comment",7],[/\/\*\*/g,"sh_comment",8],[/\/\*/g,"sh_comment",9],[/\b(?:abstract|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|final|finally|for|function|goto|if|implements|in|instanceof|interface|native|new|null|private|protected|prototype|public|return|static|super|switch|synchronized|throw|throws|this|transient|true|try|typeof|var|volatile|while|with)\b/g,"sh_keyword",-1],[/(\+\+|--|\)|\])(\s*)(\/=?(?![*\/]))/g,["sh_symbol","sh_normal","sh_symbol"],-1],[/(0x[A-Fa-f0-9]+|(?:[\d]*\.)?[\d]+(?:[eE][+-]?[\d]+)?)(\s*)(\/(?![*\/]))/g,["sh_number","sh_normal","sh_symbol"],-1],[/([A-Za-z$_][A-Za-z0-9$_]*\s*)(\/=?(?![*\/]))/g,["sh_normal","sh_symbol"],-1],[/\/(?:\\.|[^*\\\/])(?:\\.|[^\\\/])*\/[gim]*/g,"sh_regexp",-1],[/\b[+-]?(?:(?:0x[A-Fa-f0-9]+)|(?:(?:[\d]*\.)?[\d]+(?:[eE][+-]?[\d]+)?))u?(?:(?:int(?:8|16|32|64))|L)?\b/g,"sh_number",-1],[/"/g,"sh_string",10],[/'/g,"sh_string",11],[/~|!|%|\^|\*|\(|\)|-|\+|=|\[|\]|\\|:|;|,|\.|\/|\?|&|<|>|\|/g,"sh_symbol",-1],[/\{|\}/g,"sh_cbracket",-1],[/\b(?:Math|Infinity|NaN|undefined|arguments)\b/g,"sh_predef_var",-1],[/\b(?:Array|Boolean|Date|Error|EvalError|Function|Number|Object|RangeError|ReferenceError|RegExp|String|SyntaxError|TypeError|URIError|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|isNaN|parseFloat|parseInt)\b/g,"sh_predef_func",-1],[/(?:[A-Za-z]|_)[A-Za-z0-9_]*(?=[ \t]*\()/g,"sh_function",-1]],[[/$/g,null,-2],[/(?:?)|(?:?)/g,"sh_url",-1],[/<\?xml/g,"sh_preproc",2,1],[//g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)/g,"sh_keyword",6,1],[/&(?:[A-Za-z0-9]+);/g,"sh_preproc",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,"sh_keyword",6,1],[/@[A-Za-z]+/g,"sh_type",-1],[/(?:TODO|FIXME|BUG)(?:[:]?)/g,"sh_todo",-1]],[[/\?>/g,"sh_preproc",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",3]],[[/\\(?:\\|")/g,null,-1],[/"/g,"sh_string",-2]],[[/>/g,"sh_preproc",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",3]],[[/-->/g,"sh_comment",-2],[/