Skip to content

Commit 4cf0ce5

Browse files
tshinnicbnoordhuis
authored andcommitted
docs: typos and minor edits in several modules
Mostly quite minor edits. Those possibly of more interest are: emitter.setMaxListeners(n) That the limit is per event name for an emitter. fs.readlink() Not a path, but rather the symbolic link's string value, which would be at best a partial path, certainly not a 'resolvedPath' global.__filename This may be "well-known" but this is a full path to the module that referencing code is running in. It is not the main program's path, unless you are in the main program. Each module knows only its own path. server.listen(port,...) I actually needed this functionality... "gimme just _any_ next port" stream.end() stream.destroy() Yeah, everybody knows what happens to the queued data, but let's make it *really* explicit for the first readers.
1 parent fb93ab4 commit 4cf0ce5

9 files changed

Lines changed: 83 additions & 46 deletions

File tree

doc/api/events.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Adds a listener to the end of the listeners array for the specified event.
3535

3636
#### emitter.once(event, listener)
3737

38-
Adds a **one time** listener for the event. The listener is
39-
invoked only the first time the event is fired, after which
38+
Adds a **one time** listener for the event. This listener is
39+
invoked only the next time the event is fired, after which
4040
it is removed.
4141

4242
server.once('connection', function (stream) {
@@ -64,7 +64,7 @@ Removes all listeners, or those of the specified event.
6464
#### emitter.setMaxListeners(n)
6565

6666
By default EventEmitters will print a warning if more than 10 listeners are
67-
added to it. This is a useful default which helps finding memory leaks.
67+
added for a particular event. This is a useful default which helps finding memory leaks.
6868
Obviously not all Emitters should be limited to 10. This function allows
6969
that to be increased. Set to zero for unlimited.
7070

@@ -77,7 +77,7 @@ manipulated, e.g. to remove listeners.
7777
server.on('connection', function (stream) {
7878
console.log('someone connected!');
7979
});
80-
console.log(util.inspect(server.listeners('connection')); // [ [Function] ]
80+
console.log(util.inspect(server.listeners('connection'))); // [ [Function] ]
8181

8282
#### emitter.emit(event, [arg1], [arg2], [...])
8383

doc/api/fs.markdown

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ The arguments passed to the completion callback depend on the method, but the
99
first argument is always reserved for an exception. If the operation was
1010
completed successfully, then the first argument will be `null` or `undefined`.
1111

12+
When using the synchronous form any exceptions are immediately thrown.
13+
You can use try/catch to handle exceptions or allow them to bubble up.
14+
1215
Here is an example of the asynchronous version:
1316

1417
var fs = require('fs');
@@ -75,7 +78,7 @@ Synchronous ftruncate(2).
7578

7679
### fs.chown(path, uid, gid, [callback])
7780

78-
Asycnronous chown(2). No arguments other than a possible exception are given
81+
Asynchronous chown(2). No arguments other than a possible exception are given
7982
to the completion callback.
8083

8184
### fs.chownSync(path, uid, gid)
@@ -84,7 +87,7 @@ Synchronous chown(2).
8487

8588
### fs.fchown(path, uid, gid, [callback])
8689

87-
Asycnronous fchown(2). No arguments other than a possible exception are given
90+
Asynchronous fchown(2). No arguments other than a possible exception are given
8891
to the completion callback.
8992

9093
### fs.fchownSync(path, uid, gid)
@@ -93,7 +96,7 @@ Synchronous fchown(2).
9396

9497
### fs.lchown(path, uid, gid, [callback])
9598

96-
Asycnronous lchown(2). No arguments other than a possible exception are given
99+
Asynchronous lchown(2). No arguments other than a possible exception are given
97100
to the completion callback.
98101

99102
### fs.lchownSync(path, uid, gid)
@@ -194,16 +197,16 @@ Synchronous symlink(2).
194197
### fs.readlink(path, [callback])
195198

196199
Asynchronous readlink(2). The callback gets two arguments `(err,
197-
resolvedPath)`.
200+
linkString)`.
198201

199202
### fs.readlinkSync(path)
200203

201-
Synchronous readlink(2). Returns the resolved path.
204+
Synchronous readlink(2). Returns the symbolic link's string value.
202205

203206
### fs.realpath(path, [callback])
204207

205208
Asynchronous realpath(2). The callback gets two arguments `(err,
206-
resolvedPath)`.
209+
resolvedPath)`. May use `process.cwd` to resolve relative paths.
207210

208211
### fs.realpathSync(path)
209212

@@ -316,7 +319,7 @@ current position.
316319
See pwrite(2).
317320

318321
The callback will be given three arguments `(err, written, buffer)` where `written`
319-
specifies how many _bytes_ were written into `buffer`.
322+
specifies how many _bytes_ were written from `buffer`.
320323

321324
Note that it is unsafe to use `fs.write` multiple times on the same file
322325
without waiting for the callback. For this scenario,
@@ -329,7 +332,7 @@ written.
329332

330333
### fs.writeSync(fd, str, position, encoding='utf8')
331334

332-
Synchronous version of string-based `fs.write()`. Returns the number of bytes
335+
Synchronous version of string-based `fs.write()`. Returns the number of _bytes_
333336
written.
334337

335338
### fs.read(fd, buffer, offset, length, position, [callback])

doc/api/globals.markdown

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Global Objects
22

3-
These object are available in all modules. Some of these objects aren't
3+
These objects are available in all modules. Some of these objects aren't
44
actually in the global scope but in the module scope - this will be noted.
55

66
### global
@@ -43,8 +43,10 @@ value from this object, the next `require` will reload the module.
4343

4444
### __filename
4545

46-
The filename of the script being executed. This is the absolute path, and not necessarily
47-
the same filename passed in as a command line argument.
46+
The filename of the code being executed. This is the resolved absolute path
47+
of this code file. For a main program this is not necessarily the same
48+
filename used in the command line. The value inside a module is the path
49+
to that module file.
4850

4951
Example: running `node example.js` from `/Users/mjr`
5052

@@ -55,7 +57,7 @@ Example: running `node example.js` from `/Users/mjr`
5557

5658
### __dirname
5759

58-
The dirname of the script being executed.
60+
The name of the directory that the currently executing script resides in.
5961

6062
Example: running `node example.js` from `/Users/mjr`
6163

doc/api/http.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ This is an `EventEmitter` with the following events:
3131

3232
`function (request, response) { }`
3333

34-
Emitted each time there is request. Note that there may be multiple requests
34+
Emitted each time there is a request. Note that there may be multiple requests
3535
per connection (in the case of keep-alive connections).
3636
`request` is an instance of `http.ServerRequest` and `response` is
3737
an instance of `http.ServerResponse`
@@ -302,7 +302,7 @@ status code which was sent out.
302302
### response.setHeader(name, value)
303303

304304
Sets a single header value for implicit headers. If this header already exists
305-
in the to-be-sent headers, it's value will be replaced. Use an array of strings
305+
in the to-be-sent headers, its value will be replaced. Use an array of strings
306306
here if you need to send multiple headers with the same name.
307307

308308
Example:

doc/api/net.markdown

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ The arguments for this method change the type of connection:
3535

3636
Creates unix socket connection to `path`
3737

38-
The `callback` parameter will be added as an listener for the 'connect` event.
38+
The `callback` parameter will be added as an listener for the `'connect'` event.
3939

4040
---
4141

4242
### net.Server
4343

4444
This class is used to create a TCP or UNIX server.
45+
A server is a `net.Socket` that can listen for new incoming connections.
4546

4647
Here is an example of a echo server which listens for connections
4748
on port 8124:
@@ -66,20 +67,18 @@ Use `nc` to connect to a UNIX domain socket server:
6667

6768
nc -U /tmp/echo.sock
6869

69-
`net.Server` is an `EventEmitter` with the following events:
70-
7170
#### server.listen(port, [host], [callback])
7271

7372
Begin accepting connections on the specified `port` and `host`. If the
7473
`host` is omitted, the server will accept connections directed to any
75-
IPv4 address (`INADDR_ANY`).
74+
IPv4 address (`INADDR_ANY`). A port value of zero will assign a random port.
7675

7776
This function is asynchronous. The last parameter `callback` will be called
7877
when the server has been bound.
7978

80-
One issue some users run into is getting `EADDRINUSE` errors. Meaning
79+
One issue some users run into is getting `EADDRINUSE` errors. This means that
8180
another server is already running on the requested port. One way of handling this
82-
would be to wait a second and the try again. This can be done with
81+
would be to wait a second and then try again. This can be done with
8382

8483
server.on('error', function (e) {
8584
if (e.code == 'EADDRINUSE') {
@@ -149,6 +148,15 @@ Set this property to reject connections when the server's connection count gets
149148

150149
The number of concurrent connections on the server.
151150

151+
152+
`net.Server` is an `EventEmitter` with the following events:
153+
154+
#### Event: 'listening'
155+
156+
`function () {}`
157+
158+
Emitted when the server has been bound after calling `server.listen`.
159+
152160
#### Event: 'connection'
153161

154162
`function (socket) {}`
@@ -162,17 +170,22 @@ Emitted when a new connection is made. `socket` is an instance of
162170

163171
Emitted when the server closes.
164172

173+
#### Event: 'error'
174+
175+
`function (exception) {}`
176+
177+
Emitted when an error occurs. The `'close'` event will be called directly
178+
following this event. See example in discussion of `server.listen`.
179+
165180
---
166181

167182
### net.Socket
168183

169-
This object is an abstraction of of a TCP or UNIX socket. `net.Socket`
184+
This object is an abstraction of a TCP or UNIX socket. `net.Socket`
170185
instances implement a duplex Stream interface. They can be created by the
171186
user and used as a client (with `connect()`) or they can be created by Node
172187
and passed to the user through the `'connection'` event of a server.
173188

174-
`net.Socket` instances are EventEmitters with the following events:
175-
176189
#### new net.Socket([options])
177190

178191
Construct a new socket object.
@@ -212,7 +225,7 @@ event.
212225
#### socket.bufferSize
213226

214227
`net.Socket` has the property that `socket.write()` always works. This is to
215-
help users get up an running quickly. The computer cannot necessarily keep up
228+
help users get up and running quickly. The computer cannot always keep up
216229
with the amount of data that is written to a socket - the network connection simply
217230
might be too slow. Node will internally queue up the data written to a socket and
218231
send it out over the wire when it is possible. (Internally it is polling on
@@ -225,7 +238,7 @@ written, but the buffer may contain strings, and the strings are lazily
225238
encoded, so the exact number of bytes is not known.)
226239

227240
Users who experience large or growing `bufferSize` should attempt to
228-
"throttle" the data flows in their program with `pause()` and resume()`.
241+
"throttle" the data flows in their program with `pause()` and `resume()`.
229242

230243

231244
#### socket.setEncoding(encoding=null)
@@ -260,7 +273,7 @@ event on the other end.
260273

261274
#### socket.end([data], [encoding])
262275

263-
Half-closes the socket. I.E., it sends a FIN packet. It is possible the
276+
Half-closes the socket. i.e., it sends a FIN packet. It is possible the
264277
server will still send some data.
265278

266279
If `data` is specified, it is equivalent to calling `socket.write(data, encoding)`
@@ -332,12 +345,13 @@ The amount of received bytes.
332345
The amount of bytes sent.
333346

334347

348+
`net.Socket` instances are EventEmitters with the following events:
335349

336350
#### Event: 'connect'
337351

338352
`function () { }`
339353

340-
Emitted when a socket connection successfully is established.
354+
Emitted when a socket connection is successfully established.
341355
See `connect()`.
342356

343357
#### Event: 'data'
@@ -377,6 +391,8 @@ See also: `socket.setTimeout()`
377391

378392
Emitted when the write buffer becomes empty. Can be used to throttle uploads.
379393

394+
See also: the return values of `socket.write()`
395+
380396
#### Event: 'error'
381397

382398
`function (exception) { }`

doc/api/path.markdown

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
## Path
22

3-
This module contains utilities for dealing with file paths. Use
4-
`require('path')` to use it. It provides the following methods:
3+
This module contains utilities for handling and transforming file
4+
paths. Almost all these methods perform only string transformations.
5+
The file system is not consulted to check whether paths are valid.
6+
7+
`path.exists` and `path.existsSync` are the exceptions, and should
8+
logically be found in the fs module as they do access the file system.
9+
10+
Use `require('path')` to use this module. The following methods are provided:
511

612
### path.normalize(p)
713

814
Normalize a string path, taking care of `'..'` and `'.'` parts.
915

10-
When multiple slashes are found, they're replaces by a single one;
16+
When multiple slashes are found, they're replaced by a single one;
1117
when the path contains a trailing slash, it is preserved.
1218
On windows backslashes are used.
1319

@@ -75,8 +81,9 @@ Examples:
7581

7682
Solve the relative path from `from` to `to`.
7783

78-
Sometimes we've got two absolute pathes, and we need to calculate the relative path from one to another.
79-
It's accually the reverse transform of path.resolve, which means we assume:
84+
At times we have two absolute paths, and we need to derive the relative
85+
path from one to the other. This is actually the reverse transform of
86+
`path.resolve`, which means we see that:
8087

8188
path.resolve(from, path.relative(from, to)) == path.resolve(to)
8289

@@ -116,22 +123,27 @@ Example:
116123

117124
### path.extname(p)
118125

119-
Return the extension of the path. Everything after the last '.' in the last portion
120-
of the path. If there is no '.' in the last portion of the path or the only '.' is
121-
the first character, then it returns an empty string. Examples:
126+
Return the extension of the path, from the last '.' to end of string
127+
in the last portion of the path. If there is no '.' in the last portion
128+
of the path or the first character of it is '.', then it returns
129+
an empty string. Examples:
122130

123131
path.extname('index.html')
124132
// returns
125133
'.html'
126134

135+
path.extname('index.')
136+
// returns
137+
'.'
138+
127139
path.extname('index')
128140
// returns
129141
''
130142

131143
### path.exists(p, [callback])
132144

133-
Test whether or not the given path exists. Then, call the `callback` argument
134-
with either true or false. Example:
145+
Test whether or not the given path exists by checking with the file system.
146+
Then call the `callback` argument with either true or false. Example:
135147

136148
path.exists('/etc/passwd', function (exists) {
137149
util.debug(exists ? "it's there" : "no passwd!");

doc/api/stdio.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## console
22

3-
Browser-like object for printing to stdout and stderr.
3+
For printing to stdout and stderr. Similar to the console object functions
4+
provided by most web browsers, here the output is sent to stdout or stderr.
5+
46

57
### console.log()
68

doc/api/streams.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ A `Writable Stream` has the following methods, members, and events.
112112

113113
`function () { }`
114114

115-
Emitted after a `write()` method was called that returned `false` to
115+
After a `write()` method returned `false`, this event is emitted to
116116
indicate that it is safe to write again.
117117

118118
### Event: 'error'
@@ -159,6 +159,7 @@ Same as the above except with a raw buffer.
159159
### stream.end()
160160

161161
Terminates the stream with EOF or FIN.
162+
This call will allow queued write data to be sent before closing the stream.
162163

163164
### stream.end(string, encoding)
164165

@@ -172,6 +173,7 @@ Same as above but with a `buffer`.
172173
### stream.destroy()
173174

174175
Closes the underlying file descriptor. Stream will not emit any more events.
176+
Any queued write data will not be sent.
175177

176178
### stream.destroySoon()
177179

0 commit comments

Comments
 (0)