我无法使用Node连接到Redshift数据库。我正在使用Node JS版本14.15.1
。
是否与该版本有关的问题?
以下代码,我在本地机器上尝试过,
redshift.js
文件
var Redshift = require('node-redshift');
var client = {
user: 'user',
database: 'db',
password: 'password',
port: port,
host: 'hostname',
};
var redshiftClient = new Redshift(client, {rawConnection:true});
module.exports = redshiftClient;
以下是从数据库获取值的代码,位于
index.js
文件中。var redshiftClient = require('./redshift.js');
console.log('Before Connection');
redshiftClient.connect(function(err){
console.log('After Connection');
if(err) throw err;
else{
redshiftClient.query('SELECT * FROM "customer"', {raw: true}, function(err, data){
if(err) throw err;
else{
console.log(data);
redshiftClient.close();
}
});
}
});
如果我运行这段代码没有出现错误,甚至这一行也没有执行:
console.log('After Connection');