【发布时间】:2021-09-02 01:47:27
【问题描述】:
我无法使用 Node.js 连接到 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');
【问题讨论】:
-
我使用的是节点版本 12.13.1,问题已为我解决。
-
我在 AWS Lambda 函数中使用的代码相同,但响应为空。为什么?
-
请点击链接,此代码对我有用。 stackoverflow.com/questions/68080267/…
标签: node.js amazon-web-services aws-lambda amazon-redshift