Browse Source

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 <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
v4.x
lazlojuly 8 years ago
committed by Myles Borins
parent
commit
3a3fde69c7
  1. 9
      doc/api/stream.md

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

Loading…
Cancel
Save