【发布时间】:2017-12-23 18:07:00
【问题描述】:
似乎有很多文档(例如https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-node-js,但也包括本网站在内的其他地方)表明与 pg.js 节点包连接的正确方法是使用 pg.connect。但是,我尝试(在我的实际代码出现之前的问题之后)使用上述 Heroku 文档中显示的确切代码进行测试:
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 不是函数”。发生了什么,我该如何解决?
【问题讨论】: