I tried connecting to my cassandra cluster [version 1.0.6] via nodejs using node-cassandra-client
This is my sample script
var Connection = require('cassandra-client').Connection;
var con = new Connection({host:'x.x.x.x', port:9160, keyspace:'Stats', timeout:10000});
console.log(con);
con.execute('UPDATE TestCF ?=? WHERE key=?', ['cola', '1', '20120132'], function(err) {
if (err) {
console.log("Failed");
} else {
console.log("success");
}
});
On executing the script
The "sys" module is now called "util". It should have a similar interface.
node-cassandra-client.driver: connecting x.x.x.x:9160 {}
{ validators: {},
client: null,
connectionInfo:
{ host: 'x.x.x.x',
port: 9160,
keyspace: 'Stats',
timeout: 10000 },
timeout: 10000 }
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot call method 'execute_cql_query' of null
at [object Object].execute (/home/tamil/workspace/TestProjects/node-cass/node_modules/cassandra-client/lib/driver.js:367:17)
at Object.<anonymous> (/home/tamil/workspace/TestProjects/node-cass/index.js:5:5)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Array.0 (module.js:470:10)
at EventEmitter._tickCallback (node.js:192:40)
My nodetool stats
Address DC Rack Status State Load Owns Token
x.x.x.x datacenter1 rack1 Up Normal 1.03 MB 100.00% 0
What would be the error reason? and Need some help to fix this
the client inside your connection is null. You need to connect() first. Here’s an example (ignores all errors):
I recommend using async to handle the ordering of connct, query, close, etc.