From: Ryan Dahl Date: Thu, 14 Jul 2011 22:52:08 +0000 (-0700) Subject: Merge branch 'v0.4' X-Git-Tag: v0.5.1~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=041c9832902f1258c6b0f93a5d0e800cdfa70f5b;p=platform%2Fupstream%2Fnodejs.git Merge branch 'v0.4' Conflicts: deps/libev/wscript doc/api/modules.markdown --- 041c9832902f1258c6b0f93a5d0e800cdfa70f5b diff --cc doc/api/http.markdown index cc99da5,7fe5240..7af5385 --- a/doc/api/http.markdown +++ b/doc/api/http.markdown @@@ -475,15 -478,9 +479,15 @@@ an HTTP server. Normally `Agent` instan code, however in certain situations it's useful to check the status of the agent. The `http.getAgent()` function allows you to access the agents. +Options: + +- `host`: A domain name or IP address of the server to issue the request to. +- `port`: Port of remote server. +- `socketPath`: Unix Domain Socket (use one of host:port or socketPath) + ### Event: 'upgrade' - `function (response, socket, head)` + `function (response, socket, head) { }` Emitted each time a server responds to a request with an upgrade. If this event isn't being listened for, clients receiving an upgrade header will have diff --cc doc/api/modules.markdown index 9dfa1c4,59f545e..30e0636 --- a/doc/api/modules.markdown +++ b/doc/api/modules.markdown @@@ -318,56 -307,6 +318,55 @@@ Because `module` provides a `filename` `__filename`), the entry point of the current application can be obtained by checking `require.main.filename`. - +## AMD Compatibility + +Node's modules have access to a function named `define`, which may be +used to specify the module's return value. This is not necessary in node +programs, but is present in the node API in order to provide +compatibility with module loaders that use the Asynchronous Module +Definition pattern. + +The example module above could be structured like so: + + define(function (require, exports, module) { + var PI = Math.PI; + + exports.area = function (r) { + return PI * r * r; + }; + + exports.circumference = function (r) { + return 2 * PI * r; + }; + }); + +* Only the last argument to `define()` matters. Other module loaders + sometimes use a `define(id, [deps], cb)` pattern, but since this is + not relevant in node programs, the other arguments are ignored. +* If the `define` callback returns a value other than `undefined`, then + that value is assigned to `module.exports`. +* **Important**: Despite being called "AMD", the node module loader **is + in fact synchronous**, and using `define()` does not change this fact. + Node executes the callback immediately, so please plan your programs + accordingly. + + +### Accessing the main module + +When a file is run directly from Node, `require.main` is set to its +`module`. That means that you can determine whether a file has been run +directly by testing + + require.main === module + +For a file `foo.js`, this will be `true` if run via `node foo.js`, but +`false` if run by `require('./foo')`. + +Because `module` provides a `filename` property (normally equivalent to +`__filename`), the entry point of the current application can be obtained +by checking `require.main.filename`. + + ## Addenda: Package Manager Tips The semantics of Node's `require()` function were designed to be general