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(); }); });