gpt4 book ai didi

node.js - DeprecationWarning : timers. unenroll() 已弃用。请改用 clearTimeout

转载 作者:搜寻专家 更新时间:2023-11-01 00:09:53 24 4
gpt4 key购买 nike

关注这个 youtube video了解 node.js

我遇到了这个错误

$ nodemon index.js
(node:18129) [DEP0096] DeprecationWarning: timers.unenroll() is deprecated. Please use clearTimeout instead.

应用服务器仍然可以运行。但是,当我尝试添加路由器以将项目添加为视频时,它从未成功通过。但是,我会称之为半成功,因为我确实在终端中看到了数据日志,但再也没有返回到数据库。如您所见,在我查询之后,我们可以在终端中看到 xxx as name as 40 as price

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`)


});

最佳答案

npm install mysql@2.16.0 --save

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

关于node.js - DeprecationWarning : timers. unenroll() 已弃用。请改用 clearTimeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50072849/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com