From 3a3fde69c7050e505836d7ceb0b52fbc44592f9e 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 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index c2cf1d4f5a79e4..5a437459c6700f 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -67,16 +67,15 @@ var server = http.createServer( (req, res) => { // the end event tells you that you have entire body req.on('end', () => { try { - var data = JSON.parse(body); + 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(); }); });