From 1d97ce0cdc09196d5368d46e2af93e331c3d80c1 Mon Sep 17 00:00:00 2001 From: Dirceu Pereira Tiegs Date: Sun, 21 Feb 2016 15:07:27 -0300 Subject: [PATCH] doc: clarify error handling in net.createServer Remove indications that an error argument is sent to the `listen()` callback. Fixes: https://github.com/nodejs/node/issues/5345 PR-URL: https://github.com/nodejs/node/pull/5353 Reviewed-By: Evan Lucas Reviewed-By: James M Snell Reviewed-By: Trevor Norris --- doc/api/net.markdown | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/doc/api/net.markdown b/doc/api/net.markdown index 20e06d1635d50f..bc8aa1a8022dd0 100644 --- a/doc/api/net.markdown +++ b/doc/api/net.markdown @@ -48,11 +48,13 @@ Example: ```js var server = net.createServer((socket) => { socket.end('goodbye\n'); +}).on('error', (err) => { + // handle errors here + throw err; }); // grab a random port. -server.listen((err) => { - if (err) throw err; +server.listen(() => { address = server.address(); console.log('opened server on %j', address); }); @@ -655,9 +657,10 @@ const server = net.createServer((c) => { c.write('hello\r\n'); c.pipe(c); }); -server.listen(8124, (err) => { - // 'listening' listener - if (err) throw err; +server.on('error', (err) => { + throw err; +}); +server.listen(8124, () => { console.log('server bound'); }); ``` @@ -672,9 +675,8 @@ To listen on the socket `/tmp/echo.sock` the third line from the last would just be changed to ```js -server.listen('/tmp/echo.sock', (err) => { - // 'listening' listener - if (err) throw err; +server.listen('/tmp/echo.sock', () => { + console.log('server bound'); }); ```