Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc updates from joyent/node #2378

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/api/child_process.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ and the `.connected` property is false.
* `message` {Object} a parsed JSON object or primitive value
* `sendHandle` {Handle object} a Socket or Server object

Messages send by `.send(message, [sendHandle])` are obtained using the
Messages sent by `.send(message, [sendHandle])` are obtained using the
`message` event.

### child.stdin
Expand Down Expand Up @@ -315,7 +315,7 @@ process.
special.send('socket', socket);
return;
}
// just the usual dudes
// just the usual...
normal.send('socket', socket);
});
server.listen(1337);
Expand Down
4 changes: 2 additions & 2 deletions doc/api/cluster.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ all share server ports.
});
} else {
// Workers can share any TCP connection
// In this case its a HTTP server
// In this case it is an HTTP server
http.createServer(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
Expand Down Expand Up @@ -384,7 +384,7 @@ it can be obtained using `cluster.worker`.

### worker.id

* {String}
* {Number}

Each new worker is given its own unique id, this id is stored in the
`id`.
Expand Down
4 changes: 2 additions & 2 deletions doc/api/crypto.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Returned by `crypto.createHash`.

Updates the hash content with the given `data`, the encoding of which
is given in `input_encoding` and can be `'utf8'`, `'ascii'` or
`'binary'`. If no encoding is provided and the input is a string an
`'binary'`. If no encoding is provided, and the input is a string, an
encoding of `'binary'` is enforced. If `data` is a `Buffer` then
`input_encoding` is ignored.

Expand Down Expand Up @@ -323,7 +323,7 @@ called.

You can disable auto padding if the data has been encrypted without
standard block padding to prevent `decipher.final` from checking and
removing it. Can only work if the input data's length is a multiple of
removing it. This will only work if the input data's length is a multiple of
the ciphers block size. You must call this before streaming data to
`decipher.update`.

Expand Down
7 changes: 4 additions & 3 deletions doc/api/dgram.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,16 @@ a packet might travel, and that generally sending a datagram greater than
the (receiver) `MTU` won't work (the packet gets silently dropped, without
informing the source that the data did not reach its intended recipient).

### socket.bind(port[, address][, callback])
### socket.bind([port][, address][, callback])

* `port` Integer
* `port` Integer, Optional
* `address` String, Optional
* `callback` Function with no parameters, Optional. Callback when
binding is done.

For UDP sockets, listen for datagrams on a named `port` and optional
`address`. If `address` is not specified, the OS will try to listen on
`address`. If `port` is not specified, the OS will try to bind to a random
port. If `address` is not specified, the OS will try to listen on
all addresses. After binding is done, a "listening" event is emitted
and the `callback`(if specified) is called. Specifying both a
"listening" event listener and `callback` is not harmful but not very
Expand Down
2 changes: 1 addition & 1 deletion doc/api/domain.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ process. Of course, in a normal web server, you might have many
connections open, and it is not reasonable to abruptly shut those down
because an error was triggered by someone else.

The better approach is send an error response to the request that
The better approach is to send an error response to the request that
triggered the error, while letting the others finish in their normal
time, and stop listening for new requests in that worker.

Expand Down
22 changes: 9 additions & 13 deletions doc/api/fs.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ File I/O is provided by simple wrappers around standard POSIX functions. To
use this module do `require('fs')`. All the methods have asynchronous and
synchronous forms.

The asynchronous form always take a completion callback as its last argument.
The asynchronous form always takes a completion callback as its last argument.
The arguments passed to the completion callback depend on the method, but the
first argument is always reserved for an exception. If the operation was
completed successfully, then the first argument will be `null` or `undefined`.
Expand Down Expand Up @@ -59,8 +59,8 @@ In busy processes, the programmer is _strongly encouraged_ to use the
asynchronous versions of these calls. The synchronous versions will block
the entire process until they complete--halting all connections.

Relative path to filename can be used, remember however that this path will be
relative to `process.cwd()`.
The relative path to a filename can be used. Remember, however, that this path
will be relative to `process.cwd()`.

Most fs functions let you omit the callback argument. If you do, a default
callback is used that rethrows errors. To get a trace to the original call
Expand Down Expand Up @@ -574,7 +574,7 @@ stat object:

These stat objects are instances of `fs.Stat`.

If you want to be notified when the file was modified, not just accessed
If you want to be notified when the file was modified, not just accessed,
you need to compare `curr.mtime` and `prev.mtime`.

_Note: when an `fs.watchFile` operation results in an `ENOENT` error, it will
Expand Down Expand Up @@ -680,15 +680,11 @@ Then call the `callback` argument with either true or false. Example:
console.log(exists ? "it's there" : 'no passwd!');
});

`fs.exists()` is an anachronism and exists only for historical reasons.
There should almost never be a reason to use it in your own code.

In particular, checking if a file exists before opening it is an anti-pattern
that leaves you vulnerable to race conditions: another process may remove the
file between the calls to `fs.exists()` and `fs.open()`. Just open the file
and handle the error when it's not there.


`fs.exists()` should not be used to check if a file exists before calling
`fs.open()`. Doing so introduces a race condition since other processes may
change the file's state between the two calls. Instead, user code should
call `fs.open()` directly and handle the error raised if the file is
non-existent.

## fs.existsSync(path)

Expand Down
3 changes: 0 additions & 3 deletions doc/api/globals.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ when to use `module.exports`.

See the [module system documentation][] for more information.

See the [module section][] for more information.

## setTimeout(cb, ms)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is incomplete. The corresponding [module section]: modules.html has to be removed as well, as it is obsolete now.

Run callback `cb` after *at least* `ms` milliseconds. The actual delay depends
Expand Down Expand Up @@ -183,7 +181,6 @@ will not execute.
The timer functions are global variables. See the [timers][] section.

[buffer section]: buffer.html
[module section]: modules.html
[module system documentation]: modules.html
[Modules]: modules.html#modules_modules
[process object]: process.html#process_process
Expand Down
24 changes: 17 additions & 7 deletions doc/api/modules.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ plan accordingly.
Node.js has several modules compiled into the binary. These modules are
described in greater detail elsewhere in this documentation.

<<<<<<< HEAD
The core modules are defined in Node.js's source in the `lib/` folder.
=======
The core modules are defined within io.js's source and are located in the
`lib/` folder.
>>>>>>> doc: small clarifications to modules.markdown

Core modules are always preferentially loaded if their identifier is
passed to `require()`. For instance, `require('http')` will always
Expand All @@ -130,23 +135,29 @@ return the built in HTTP module, even if there is a file by that name.

<!--type=misc-->

<<<<<<< HEAD
If the exact filename is not found, then Node.js will attempt to load the
required filename with the added extension of `.js`, `.json`, and then `.node`.
=======
If the exact filename is not found, then io.js will attempt to load the
required filename with the added extensions: `.js`, `.json`, and finally
`.node`.
>>>>>>> doc: small clarifications to modules.markdown

`.js` files are interpreted as JavaScript text files, and `.json` files are
parsed as JSON text files. `.node` files are interpreted as compiled addon
modules loaded with `dlopen`.

A module prefixed with `'/'` is an absolute path to the file. For
A required module prefixed with `'/'` is an absolute path to the file. For
example, `require('/home/marco/foo.js')` will load the file at
`/home/marco/foo.js`.

A module prefixed with `'./'` is relative to the file calling `require()`.
That is, `circle.js` must be in the same directory as `foo.js` for
A required module prefixed with `'./'` is relative to the file calling
`require()`. That is, `circle.js` must be in the same directory as `foo.js` for
`require('./circle')` to find it.

Without a leading '/', './', or '../' to indicate a file, the module is either a
core module or is loaded from a `node_modules` folder.
Without a leading '/', './', or '../' to indicate a file, the module must
either be a core module or is loaded from a `node_modules` folder.

If the given path does not exist, `require()` will throw an Error with its
`code` property set to `'MODULE_NOT_FOUND'`.
Expand Down Expand Up @@ -357,8 +368,7 @@ loading.

* {Module Object}

The module that required this one.

The module that first required this one.

### module.children

Expand Down
6 changes: 3 additions & 3 deletions doc/api/net.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ Use `nc` to connect to a UNIX domain socket server:

nc -U /tmp/echo.sock

## net.connect(options[, connectionListener])
## net.createConnection(options[, connectionListener])
## net.connect(options[, connectListener])
## net.createConnection(options[, connectListener])

A factory function, which returns a new ['net.Socket'](#net_class_net_socket)
and automatically connects with the supplied `options`.
Expand Down Expand Up @@ -334,7 +334,7 @@ Construct a new socket object.

`options` is an object with the following defaults:

{ fd: null
{ fd: null,
allowHalfOpen: false,
readable: false,
writable: false
Expand Down
4 changes: 4 additions & 0 deletions doc/api/path.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ an empty string. Examples:
// returns
''

path.extname('.index')
// returns
''

## path.sep

The platform-specific file separator. `'\\'` or `'/'`.
Expand Down
25 changes: 12 additions & 13 deletions doc/api/repl.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -117,32 +117,31 @@ will share the same global object but will have unique I/O.

Here is an example that starts a REPL on stdin, a Unix socket, and a TCP socket:

var net = require("net"),
repl = require("repl");

connections = 0;
var net = require('net'),
repl = require('repl'),
connections = 0;

repl.start({
prompt: "Node.js via stdin> ",
prompt: 'Node.js via stdin> ',
input: process.stdin,
output: process.stdout
});

net.createServer(function (socket) {
connections += 1;
repl.start({
prompt: "Node.js via Unix socket> ",
prompt: 'Node.js via Unix socket> ',
input: socket,
output: socket
}).on('exit', function() {
socket.end();
})
}).listen("/tmp/node-repl-sock");
}).listen('/tmp/node-repl-sock');

net.createServer(function (socket) {
connections += 1;
repl.start({
prompt: "Node.js via TCP socket> ",
prompt: 'Node.js via TCP socket> ',
input: socket,
output: socket
}).on('exit', function() {
Expand Down Expand Up @@ -191,7 +190,7 @@ be emitted.
Example of listening for `reset`:

// Extend the initial repl context.
r = repl.start({ options ... });
var r = repl.start({ options ... });
someExtension.extend(r.context);

// When a new context is created extend it as well.
Expand All @@ -213,7 +212,7 @@ accessing `fs` will `require()` the `fs` module as `global.fs`.

The special variable `_` (underscore) contains the result of the last expression.

> [ "a", "b", "c" ]
> [ 'a', 'b', 'c' ]
[ 'a', 'b', 'c' ]
> _.length
3
Expand All @@ -225,10 +224,10 @@ a variable to the REPL explicitly by assigning it to the `context` object
associated with each `REPLServer`. For example:

// repl_test.js
var repl = require("repl"),
msg = "message";
var repl = require('repl'),
msg = 'message';

repl.start("> ").context.m = msg;
repl.start('> ').context.m = msg;

Things in the `context` object appear as local within the REPL:

Expand Down
15 changes: 9 additions & 6 deletions doc/api/stream.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,11 @@ readable.on('end', function() {

#### Event: 'close'

Emitted when the underlying resource (for example, the backing file
descriptor) has been closed. Not all streams will emit this.
Emitted when the stream and any of its underlying resources (a file
descriptor, for example) have been closed. The event indicates that
no more events will be emitted, and no further computation will occur.

Not all streams will emit the 'close' event.

#### Event: 'error'

Expand Down Expand Up @@ -1215,19 +1218,19 @@ as a result of this chunk.

Call the callback function only when the current chunk is completely
consumed. Note that there may or may not be output as a result of any
particular input chunk. If you supply output as the second argument to the
callback, it will be passed to push method, in other words the following are
particular input chunk. If you supply a second argument to the callback
it will be passed to the push method. In other words the following are
equivalent:

```javascript
transform.prototype._transform = function (data, encoding, callback) {
this.push(data);
callback();
}
};

transform.prototype._transform = function (data, encoding, callback) {
callback(null, data);
}
};
```

This method is prefixed with an underscore because it is internal to
Expand Down