From 82329b6e8fe3fd364e13869cc3387eb4e68a7ecc Mon Sep 17 00:00:00 2001 From: lazlojuly Date: Tue, 16 Aug 2016 17:56:52 +0100 Subject: [PATCH] doc: fix variable scoping bug in server example code Const is block scoped. PR-URL: https://github.com/nodejs/node/pull/8124 Reviewed-By: James M Snell Reviewed-By: Myles Borins --- doc/api/stream.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index 16644f8e2257c8..72baca9c4ab050 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -130,15 +130,14 @@ const server = http.createServer( (req, res) => { req.on('end', () => { try { const data = JSON.parse(body); + // write back something interesting to the user: + res.write(typeof data); + res.end(); } catch (er) { // uh oh! bad json! res.statusCode = 400; return res.end(`error: ${er.message}`); } - - // write back something interesting to the user: - res.write(typeof data); - res.end(); }); });