2011-11-11 36 views
3

为什么使用pg module运行查询会阻止进程终止?为什么在node.js中运行此查询会阻止进程退出?

这段代码直接从github页面的自述文件中获取。在终端中执行此node.js脚本执行sql查询,但不立即返回到bash提示符。它可能需要大约20秒退出。

var pg = require('pg'); 
var conString = "tcp://postgres:[email protected]/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()); 
    }); 
}); 
+0

是否添加“pg.end”呼叫帮助? –

+0

啊是的!作为回答发布,我会标记它。 –

回答

3

你只需要调用pg.end

相关问题