7

I am not able to connect to the redshift database using Node. I am using Node JS version 14.15.1. Is there any issue related to this version?

The following code, I have tried in my local machine, redshift.js file

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;

The following is the code to get the values from database, index.js file

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();
        }
      });
    }
  });

If I run this code not getting the error and even this line is also not executed console.log('After Connection');

4

1 Answer 1

3

The package seems a bit abandoned as here's an open issue with exact issue

To solve that you need to apply this solution manually

go to node_modules/node-redshift and replace

  "dependencies": {
    "commander": "^2.9.0",
    "migrate": "^0.2.2",
    "pg": "^6.1.2",
    "sql-bricks": "^1.2.3"
  },

in package.json to

  "dependencies": {
    "commander": "^2.9.0",
    "migrate": "^0.2.2",
    "pg": "^8.1.5",
    "sql-bricks": "^1.2.3"
  },

run npm install in this directory in order to update this package. After that your code will work

Sign up to request clarification or add additional context in comments.

1 Comment

In node_modules/node-redshift folder you have mentioned "pg": "^6.1.2", but in the package.json file the version for the pg is different ``` "pg": "^8.1.5",```. Is it the same?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.