Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 33ec175

Browse files
committedJan 24, 2016
doc: check for errors in listen event
In the docs we typically check for errors and surface them. This is IMO a good idea and good practice. This PR adds a check for errors in three places in the `net` docs where it was missing. PR-URL: #4834 Reviewed-By: Roman Reiss <[email protected]> Reviewd-By: Colin Ihrig <[email protected]>
1 parent 55607a0 commit 33ec175

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed
 

‎doc/api/net.markdown

+15-7
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ var server = net.createServer((socket) => {
5151
});
5252

5353
// grab a random port.
54-
server.listen(() => {
54+
server.listen((err) => {
55+
if (err) throw err;
5556
address = server.address();
5657
console.log('opened server on %j', address);
5758
});
@@ -528,7 +529,8 @@ Here is an example of a client of the previously described echo server:
528529

529530
```js
530531
const net = require('net');
531-
const client = net.connect({port: 8124}, () => { //'connect' listener
532+
const client = net.connect({port: 8124}, () => {
533+
// 'connect' listener
532534
console.log('connected to server!');
533535
client.write('world!\r\n');
534536
});
@@ -581,8 +583,8 @@ Here is an example of a client of the previously described echo server:
581583

582584
```js
583585
const net = require('net');
584-
const client = net.connect({port: 8124},
585-
() => { //'connect' listener
586+
const client = net.connect({port: 8124}, () => {
587+
//'connect' listener
586588
console.log('connected to server!');
587589
client.write('world!\r\n');
588590
});
@@ -649,15 +651,18 @@ on port 8124:
649651

650652
```js
651653
const net = require('net');
652-
const server = net.createServer((c) => { //'connection' listener
654+
const server = net.createServer((c) => {
655+
// 'connection' listener
653656
console.log('client connected');
654657
c.on('end', () => {
655658
console.log('client disconnected');
656659
});
657660
c.write('hello\r\n');
658661
c.pipe(c);
659662
});
660-
server.listen(8124, () => { //'listening' listener
663+
server.listen(8124, (err) => {
664+
// 'listening' listener
665+
if (err) throw err;
661666
console.log('server bound');
662667
});
663668
```
@@ -672,7 +677,10 @@ To listen on the socket `/tmp/echo.sock` the third line from the last would
672677
just be changed to
673678

674679
```js
675-
server.listen('/tmp/echo.sock', () => { /* 'listening' listener*/ })
680+
server.listen('/tmp/echo.sock', (err) => {
681+
// 'listening' listener
682+
if (err) throw err;
683+
});
676684
```
677685

678686
Use `nc` to connect to a UNIX domain socket server:

0 commit comments

Comments
 (0)
Please sign in to comment.