Blane Townsend
Blane Townsend

Reputation: 3048

How to install cassandra nodejs

I have a linux ec2 instance on amazon and have installed cassandra. I then installed nodejs and used

npm install node-cassandra-cql

to install the cassandra part of nodejs. I have tried out the basic scripts that were given:

//Creating a new connection pool to multiple hosts.
var cql = require('node-cassandra-cql');
var client = new cql.Client({hosts: ['host1', 'host2'], keyspace: 'keyspace1'});
client.execute('SELECT key, email, last_name FROM user_profiles WHERE key=?', ['jbay'],
  function(err, result) {
    if (err) console.log('execute failed');
    else console.log('got user profile with email ' + result.rows[0].email);
  }
);

The problem is I get an error on the first line saying that the require is not defined. My server says everything is installed, is there some preference that could be catching me up?

Upvotes: 0

Views: 318

Answers (1)

dylants
dylants

Reputation: 23370

If you're getting an error stating the require is not defined, perhaps you're not running this using the node binary? I was able to execute the code doing the following:

From the root of my project, I executed:

$ npm install node-cassandra-cql

I created a file, index.js in the root of my project, and added the cassandra code you pasted above to the file. I then executed (from that same directory):

$ node index.js 

Upvotes: 1

Related Questions