dmanjunath / node-redshift

A simple collection of tools to help you get started with Amazon Redshift from node.js
69 stars 48 forks source link

Issue with connecting to my database. #26

Closed jacksnipe24 closed 5 years ago

jacksnipe24 commented 6 years ago

Please help ! I have redshift cluster and from sql workbench everything works fine, i can connect and work. I tried to connect to my database from node.js server. i installed this module, tried to use, but every time i was getting

error: getaddrinfo ENOTFOUND jdbc:.... (and my jdbc link)

i tried with both raw and normal connection

here is my sample code

const Redshift = require('node-redshift');
const redShiftConnectionOptions = {
    user: 'myusername',
    database: 'mydatabase',
    password: 'mypassword',
    port: 5439,
    host: 'jdbc:redshift://my-redshift-link'
  };

  const redshiftClient = new Redshift(redShiftConnectionOptions, {
    rawConnection: true
  });

redshiftClient.connect(function(err) {
    if (err) {
      console.log('error is here');
      throw err;
    } else {
      redshiftClient.query('select * from "photo_tags"', function(err, data) {
        if (err) throw err;
        else {
          res.send(data);
          redshiftClient.close();
        }
      });
    }
  });

Every time it goes to connection error.

Tomarr commented 5 years ago

Hi, Did you find the answer for this? I am also getting the same error. Can you please let us know whether it is because of the host name? or something else?

Thanks.

jacksnipe24 commented 5 years ago

hey @Tomarr . i was passing wrong configuration object. in the example above host name is like host: 'jdbc:redshift://my-redshift-link' instead it should be

 host: encodeURI(
        'redshift-cluster-...........'
    )