DeprecationWarning:不推荐使用timers.unenroll()。请改用clearTimeout

时间:2018-04-28 04:28:14

标签: node.js

关注此youtube video以了解node.js

我收到了这个错误

  

$ nodemon index.js
  (node:18129)[DEP0096] DeprecationWarning:不推荐使用timers.unenroll()。请改用clearTimeout。

App服务器仍然可以运行。但是,当我尝试添加路由器以添加项目作为视频时,它从未成功通过。但是,我会称之为半成功,因为我确实看到了终端中的数据日志,但从未返回数据库。正如您所看到的,我查询后,我们可以在终端中看到xxx名称为40作为终端价格

http://localhost:4000/products/add?name=xxx&price=40

在浏览器中,就像在10:52左右的视频中一样。 (我在index.js文件中进行了硬编码后才开始工作。为什么我不能像视频一样查询它?)我假设timers.unenorll()导致这个问题。但我用谷歌搜索它,我发现这是one,而one(在https://nodejs.org/en/blog/release/v10.0.0/页面上)

enter image description here

但不知道如何处理它。斜面'找到解决方案。请帮助

$ node -v
v10.0.0

enter image description here

const express = require('express');
const cors = require('cors');
const mysql = require('mysql');

const app = express();

app.use(cors());

const SELECT_ALL_PRODUCT_QUERY = 'SELECT * FROM products';

const connection = mysql.createConnection({
  host: 'localhost',
  user: 'genius',
  password: 'genius',
  database: 'react_sql'
});

connection.connect(err => {
  if(err) {
    return err;
  }
});

console.log(connection);


app.get('/',(req, res) => {
  res.send('go to /products to see the genius gyms')
});

app.get('/products/add', (req, res) => {
  const {name, price} = req.query;
  //console.log(name, price); 
  const INSERT_PRODUCTS_QUERY = `INSERT INTO products(name, price) VALUES('${name}',${price})`;
  connection.query(INSERT_PRODUCTS_QUERY,(err, results) => {
    if(err) {
      return res.send(err)
    } else {
      return res.send('successfully added product')
    }

  });   
  });




app.get('/products', (req, res) => {
  connection.query(SELECT_ALL_PRODUCT_QUERY,(err,results) => {
    if(err) {
      return res.send(err)
    }
    else {
      return res.json({
        data: results
      })
    }
  });
});


app.listen(4000,() => {
    console.log(`Genius gyms listening on
    port 4000`)


}); 

2 个答案:

答案 0 :(得分:13)

ImpexService

只需将mysql库更新到最新版本。

答案 1 :(得分:5)

攻击者似乎是代码中此位置的mysql模块,您看到Timers.unenroll(sequence)的调用:

https://github.com/mysqljs/mysql/blob/61b173cbc3e207c5497c6c45c98a4871c01701f3/lib/protocol/Protocol.js#L325

Protocol.prototype._dequeue = function(sequence) {
  Timers.unenroll(sequence);

  // No point in advancing the queue, we are dead
  if (this._fatalError) {
    return;
  }

  this._queue.shift();

  var sequence = this._queue[0];
  if (!sequence) {
    this.emit('drain');
    return;
  }

  this._parser.resetPacketNumber();

  this._startSequence(sequence);
};

来自node.js Github网站上的各种评论,听起来API已被弃用,但很快就不会被删除。希望mysql在某些时候会切换到替代品。如果您想了解更多信息,可以查询他们的Github网站。具体问题已在mysql网站上提交:https://github.com/mysqljs/mysql/issues/2003,当前的响应是mysql模块还不支持node.js 10.x。

这可能意味着您可以将节点版本回滚到8.x,如果您愿意,问题可能会消失,或者只是等待直接支持nodejs 10.x的mysql版本。

相关问题