Right now, I'm running a docker with Cassandra on it. I have a javascript file that sits outside the docker that needs to connect to Cassandra. I've found a node package that interfaces w/ JS, called cassandra-driver. However, with the following code:
var cassandra = require('cassandra-driver');
var PlainTextAuthProvider = cassandra.auth.PlainTextAuthProvider;
const client = new cassandra.Client({
contactPoints: ['127.0.0.1:9042'],
localDataCenter: '127.0.0.1',
keyspace: 'wasabi_experiments',
authProvider: new PlainTextAuthProvider('cassandra', 'cassandra')
});
I get
(node:17836) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): NoHostAvailableError: All host(s) tried for query failed. First host tried, 127.0.0.1:9042: ArgumentError: localDataCenter was configured as '127.0.0.1', but only found hosts in data centers: [datacenter1]. See innerErrors.
(node:17836) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): NoHostAvailableError: All host(s) tried for query failed. First host tried, 127.0.0.1:9042: ArgumentError: localDataCenter was configured as '127.0.0.1', but only found hosts in data centers: [datacenter1]. See innerErrors.
How can I get this to work?
try first with a Cassandra client, ensure Cassandra is working properly and you can access it. After that try with the code. Also you can try to access the 127.0.0.1:9042 using telnet or netcat to see if the port is open and listening. You can use netstat too for this task.