Why does this work:
const http = require('http');
http.createServer((req, res) => {
res.write(JSON.stringify(req.headers)); // req.headers ✔️
res.end();
}).listen(3000);
but this doesn't:
const http = require('http');
http.createServer((req, res) => {
res.write(JSON.stringify(req.getHeaders())); // req.getHeaders() ❌
res.end();
}).listen(3000);
..producing:
$ node script.js
<go to: http://localhost:3000/>
[...]
TypeError: req.getHeaders is not a function
..when the Node.js documentation (16.x doc is identical), even under the section titled "message.headers", clearly demonstrates the use of:
console.log(request.getHeaders());