doc: improve server.listen() random port · nodejs/node@66af6a9
@@ -73,8 +73,7 @@ var server = net.createServer((socket) => {
73737474// grab a random port.
7575server.listen(() => {
76- address = server.address();
77-console.log('opened server on %j', address);
76+console.log('opened server on', server.address());
7877});
7978```
8079@@ -140,7 +139,7 @@ The last parameter `callback` will be added as a listener for the
140139[`'listening'`][] event.
141140142141The parameter `backlog` behaves the same as in
143-[`server.listen(port[, hostname][, backlog][, callback])`][`server.listen(port, host, backlog, callback)`].
142+[`server.listen([port][, hostname][, backlog][, callback])`][`server.listen(port, host, backlog, callback)`].
144143145144### server.listen(options[, callback])
146145<!-- YAML
@@ -157,7 +156,7 @@ added: v0.11.14
157156158157The `port`, `host`, and `backlog` properties of `options`, as well as the
159158optional callback function, behave as they do on a call to
160-[`server.listen(port[, hostname][, backlog][, callback])`][`server.listen(port, host, backlog, callback)`].
159+[`server.listen([port][, hostname][, backlog][, callback])`][`server.listen(port, host, backlog, callback)`].
161160Alternatively, the `path` option can be used to specify a UNIX socket.
162161163162If `exclusive` is `false` (default), then cluster workers will use the same
@@ -209,17 +208,19 @@ double-backslashes, such as:
209208 path.join('\\\\?\\pipe', process.cwd(), 'myctl'))
210209211210The parameter `backlog` behaves the same as in
212-[`server.listen(port[, hostname][, backlog][, callback])`][`server.listen(port, host, backlog, callback)`].
211+[`server.listen([port][, hostname][, backlog][, callback])`][`server.listen(port, host, backlog, callback)`].
213212214-### server.listen(port[, hostname][, backlog][, callback])
213+### server.listen([port][, hostname][, backlog][, callback])
215214<!-- YAML
216215added: v0.1.90
217216-->
218217219218Begin accepting connections on the specified `port` and `hostname`. If the
220219`hostname` is omitted, the server will accept connections on any IPv6 address
221-(`::`) when IPv6 is available, or any IPv4 address (`0.0.0.0`) otherwise. Use a
222-port value of `0` to have the operating system assign an available port.
220+(`::`) when IPv6 is available, or any IPv4 address (`0.0.0.0`) otherwise.
221+Omit the port argument, or use a port value of `0`, to have the operating system
222+assign a random port, which can be retrieved by using `server.address().port`
223+after the `'listening'` event has been emitted.
223224224225Backlog is the maximum length of the queue of pending connections.
225226The actual length will be determined by the OS through sysctl settings such as