How to fix (node:12388) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated in windows

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().