I am new to nodes.I have install nosejs version v12.4.0, npm 6.9.0 , http-server 0.11.1 and visual studio code.I want to open my hello word project with my http-server,it is in Visual studio code. But I receive the below error
ERROR
[2019-06-21T05:20:18.280Z] "GET /" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763" (node:11596) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
I tried npm install node-gyp to fix the header problem but no success.
Also I have try to use different browsers eg. chrome, firefox , explore but no success.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1> Hello Word </h1>
</body>
</html>
I expected to see "Hello Word" in any of the browsers.I am using windows 10. Kindly assist
Node version 12 depracated OutgoingMessage.prototype._headers, which is used in http-server. Issue is listed at: https://github.com/http-party/http-server/issues/537
https://nodejs.org/api/deprecations.html#deprecations_dep0066_outgoingmessage_prototype_headers_outgoingmessage_prototype_headernames
Using node 12.0.0 I get the same error using http-server. Switching to 10.11.0 removes the error.
Those who are facing this problem in FreeCodeCamp
exercise, the issue is in the server.js
file. The solution is to replace ._headers
with .getHeaders()
, as the error is telling us that ._headers
has been deprecated.
e.g. in server.js
, instead of -
// filter out CORS Headers
var hs = Object.keys(res._headers)
.filter(h => !h.match(/^access-control-\w+/));
var hObj = {};
hs.forEach(h => {hObj[h] = res._headers[h]});
delete res._headers['strict-transport-security'];
use the following -
// filter out CORS Headers
var hs = Object.keys(res.getHeaders())
.filter(h => !h.match(/^access-control-\w+/));
var hObj = {};
hs.forEach(h => {hObj[h] = res.getHeaders()[h]});
delete res.getHeaders()['strict-transport-security'];
Summary: replace all ._headers
with .getHeaders()
.
I had some issue with browser-sync. When I started project I got warning from node ([DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated) every time. But when I updated my browser-synk dependencies to "browser-sync": "^2.26.13" my project started without any warning.
For those getting it everytime they start their project,
Run: npm i browser-sync
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With