'Connect nodejs (local) to cassandra database running on docker container

I have a nodejs API running locally and I would like to connect it to my cassandra cluster running on a docker container.

I have the IP of the container but when trying to connect I get the following error.

All host(s) tried to query failed. First host tried, {ip}: DriverError: Connection timeout

I'm trying to connect like this.

var client = new cassandra.Client({ contactPoints: ['{ip}'], keyspace:'ks1'});

    client.connect(function (err) {
        assert.ifError(err);
      });

I don't know much about docker, so some help would be appreciated. Thanks!



Solution 1:[1]

I got it working.

  1. Cant connect to the container IP but to localhost.
  2. I was missing parameters.
var client = new cassandra.Client(
    {contactPoints: ['127.0.0.1'], keyspace:'tfm',localDataCenter: 'datacenter1',}
);

This was the code that worked.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jaime Cuellar