为什么我的 node 爬虫执行完成后,不会自动退出程序?
有使用了 async await 的,执行完成后,已经手动断开了 mongodb 的链接。 结果是链接貌似已经成功断开了,但是程序却一直没有退出,导致后续的再执行就链接不上 mongodb 了。该如何解决? image.png 这是爬虫的运行代码: image.png
10 回复
@JZLeung
mysql 模块中有个mysql.createPool方法
比如:
var mysql = require('mysql');
var pool = mysql.createPool(...);
pool.getConnection(function(err, connection) {
// Use the connection
connection.query('SELECT something FROM sometable', function (error, results, fields) {
// And done with the connection.
connection.release();
// Handle error after the release.
if (error) throw error;
// Don't use the connection here, it has been returned to the pool.
});
});
具体的你可以查看文档的 mysql