@@ -73,8 +73,7 @@ var server = net.createServer((socket) => {
73
73
74
74
// grab a random port.
75
75
server .listen (() => {
76
- address = server .address ();
77
- console .log (' opened server on %j' , address);
76
+ console .log (' opened server on' , server .address ());
78
77
});
79
78
```
80
79
@@ -140,7 +139,7 @@ The last parameter `callback` will be added as a listener for the
140
139
[ ` 'listening' ` ] [ ] event.
141
140
142
141
The 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)` ] .
144
143
145
144
### server.listen(options[ , callback] )
146
145
<!-- YAML
@@ -157,7 +156,7 @@ added: v0.11.14
157
156
158
157
The ` port ` , ` host ` , and ` backlog ` properties of ` options ` , as well as the
159
158
optional 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)` ] .
161
160
Alternatively, the ` path ` option can be used to specify a UNIX socket.
162
161
163
162
If ` exclusive ` is ` false ` (default), then cluster workers will use the same
@@ -209,17 +208,19 @@ double-backslashes, such as:
209
208
path.join('\\\\?\\pipe', process.cwd(), 'myctl'))
210
209
211
210
The 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)` ] .
213
212
214
- ### server.listen(port[ , hostname] [ , backlog ] [ , callback] )
213
+ ### server.listen([ port] [ , hostname ] [ , backlog] [ , callback ] )
215
214
<!-- YAML
216
215
added: v0.1.90
217
216
-->
218
217
219
218
Begin accepting connections on the specified ` port ` and ` hostname ` . If the
220
219
` 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.
223
224
224
225
Backlog is the maximum length of the queue of pending connections.
225
226
The actual length will be determined by the OS through sysctl settings such as
0 commit comments