2

I am running an Express API with Node.js using mssql@3.3.0.

An older version of mssql is being used to align with other compatibility issues that we're having.

However, when trying to use promises to chain requests together I am getting the following error:

DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

How do I disable this warning and run the code in "unsafe" mode using IISNode / Express?

Matthew
  • 1,461
  • 3
  • 23
  • 49

2 Answers2

1

I am using node14, it also shows this warning, I tried Kade's solution, but it does not work, after search the internet, I found the code below works:

const warning = process.emitWarning;
process.emitWarning = (...args) => {
    if (args[2] !== 'DEP0005') {
        return warning.apply(process, args);
    }
}
derpedy-doo
  • 1,097
  • 1
  • 18
  • 22
SLdragon
  • 1,477
  • 16
  • 19
0

I ran into this same issue, and here is how I resolved it.

First, as suggested by this question, I added the following code to my web.config file (as a child of system.webServer):

<iisnode nodeProcessCommandLine='"C:\Program Files\nodejs\node.exe" --no-warnings' />

This made it so that all warnings were not sent to stderr. I only wanted to suppress the Buffer() Deprecation warning.

This article explains that even though the no-warnings flag is used, "the Node.js processes object will also emit the warning event". So, I then added the following code to my server.js file:

process.on('warning', (warning) => {
    if (!warning.message.includes("Buffer() is deprecated")) {
        console.error(warning);
    }
});

Now, only the Buffer() Deprecation warning is ignored.

Kade
  • 901
  • 13
  • 18