为什么使用 pg module 运行查询阻止进程终止?
这段代码直接取自 github 页面的自述文件。在终端中执行此 node.js 脚本会执行 sql 查询,但不会立即返回到 bash 提示符。退出可能需要大约 20 秒。
var pg = require('pg');
var conString = "tcp://postgres:1234@localhost/postgres";
//error handling omitted
pg.connect(conString, function(err, client) {
client.query("SELECT NOW() as when", function(err, result) {
console.log("Row count: %d",result.rows.length); // 1
console.log("Current year: %d", result.rows[0].when.getYear());
});
});
最佳答案
你只需要调用pg.end
。
关于node.js - 为什么在 node.js 中运行这个查询会阻止进程退出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8090548/