似乎有很多文档(例如https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-node-js,但也包括此站点在内的其他地方)表明正确使用pg.js节点包进行连接的方法是使用pg.connect。不过,我试图(后与我的实际代码前面的问题)通过使用上述Heroku的文档上显示的确切的代码进行测试:pg.connect不是一个函数?
var pg = require('pg');
pg.defaults.ssl = true;
pg.connect(process.env.DATABASE_URL, function(err, client) {
if (err) throw err;
console.log('Connected to postgres! Getting schemas...');
client
.query('SELECT table_schema,table_name FROM information_schema.tables;')
.on('row', function(row) {
console.log(JSON.stringify(row));
});
});
而且我得到了错误信息“pg.connect不是一个函数”。发生了什么,我该如何解决?