脚本移动到其他服务器时出错.

( node :15707)[DEP0005]弃用警告:由于安全性和可用性问题,Buffer()已弃用.请使用缓冲区.alloc(),缓冲区.allocUnsafe()或缓冲区.而不是从()方法.

当前版本:

Ubuntu 16.04.4 LTS  
Node - v10.9.0  
NPM - 6.2.0  

以前的版本:

Ubuntu 14.04.3 LTS
NPM - 3.10.10
Node - v6.10.3


exports.basicAuthentication = function (req, res, next) {
    console.log("basicAuthentication");
    if (!req.headers.authorization) {
        return res.status(401).send({
            message: "Unauthorised access"
        });
    }
    var auth = req.headers.authorization;
    var baseAuth = auth.replace("Basic", "");
    baseAuth = baseAuth.trim();
    var userPasswordString = new Buffer(baseAuth, 'base64').toString('ascii');
    var credentials = userPasswordString.split(':');

    var username = credentials[0] !== undefined ? credentials[0] : '';
    var password = credentials[1] !== undefined ? credentials[1] : '';
    var userQuery = {mobilenumber: username, otp: password};
    console.log(userQuery);
    User.findOne(userQuery).exec(function (err, userinfo) {
        if (err || !userinfo) {
             return res.status(401).send({
                message: "Unauthorised access"
             });
        } else {
            req.user = userinfo;
            next();
        }
    });

 }

推荐答案

new Buffer(number)            // Old
Buffer.alloc(number)          // New

new Buffer(string)            // Old
Buffer.from(string)           // New

new Buffer(string, encoding)  // Old
Buffer.from(string, encoding) // New

new Buffer(...arguments)      // Old
Buffer.from(...arguments)     // New

Note that Buffer.alloc() is also faster on the current Node.js versions than new Buffer(size).fill(0), which is what you would otherwise need to ensure zero-filling.

Node.js相关问答推荐

使用Node.js中的";类型";:";模块";不导入文件

Express无法发布

Node.js中Redis的并发问题

仅在一次查询中 MongoDB 上最近的一对位置

Mongoose:如何使用填充进行查找

如何在MongoDB中删除嵌套对象数组中的属性?

无法通过 NextJS 访问 HTTP 帖子中的正文

Mocha调用所有it回调模拟(测试中间件)

如何从哪个应用程序用户中找到在 Firebase 身份验证中进行身份验证的用户

Google Calendar API FreeBusy 外部用户

我怎样才能让`git`失败而不是要求提供凭据

使用 firebase 函数 api 运行套接字(相同的端口创建问题)

fs.writefile 选项参数的可能值,尤其是只读文件的整数

为什么我在生产环境中 deproy Next.js 示例项目时 CSS 不起作用?

node.js 变量不存在代码块

运行摩卡+伊斯坦布尔+通天塔

使用 Webpack 和 font-face 加载字体

如何在 MongoDB 中查询引用的对象?

如何判断 Node.js 中是否设置了环境变量?

从 JavaScript 文件或 REPL 中 require()'ing CoffeeScript 文件