Azure / iisnode

Hosting node.js applications in IIS on Windows
Other
667 stars 101 forks source link

[DEP0005] DeprecationWarning: Buffer() is deprecated ... #107

Open Larry-Rosenfeld opened 3 years ago

Larry-Rosenfeld commented 3 years ago

Hi Y'all! Thanks so much for this essential software!

Running this code on a Windows web server, supporting a node.js application, my node log file records the following warning:

(node:12064) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
    at showFlaggedDeprecation (buffer.js:192:11)
    at new Buffer (buffer.js:279:3)
    at ensureBuffer (C:\Program Files (x86)\iisnode\interceptor.js:169:24)
    at SyncWriteStream.stream.write.stream.end (C:\Program Files (x86)\iisnode\interceptor.js:174:26)
    at Object.Console.<computed> (internal/console/constructor.js:255:12)
    at Object.log (internal/console/constructor.js:300:26)

As indicated above, the problem is with interceptor.js, line 169:

return new Buffer(data, typeof encoding === 'string' ? encoding : 'utf8');

Based on https://nodejs.org/api/deprecations.html#DEP0005, I've changed this line to the following and no longer get the warning. In addition, a message truncation problem that has been plaguing me on a new Windows web server appears to have disappeared (hopefully for good ;-) ):

 return Buffer.from(data, typeof encoding === 'string' ? encoding : 'utf8');

Did I get this update right? Perhaps there's a better fix -- or perhaps there's no need for a fix and I'm wrong-tree barking? Any guidance y'all could provide is appreciated.

Larry Rosenfeld Applications Analyst, UNC-CH

hesantan commented 3 years ago

@Larry-Rosenfeld Did you checkout this issue: https://github.com/Azure/iisnode/issues/60? The changes here solved the issue on my end.

lroal commented 2 years ago

Why not merge the pull request ?

Stuart88 commented 11 months ago

Yeah this really should have been merged... or at least give a reason why it was closed.