简体   繁体   English

如何安装Cassandra Node.js

[英]How to install cassandra nodejs

I have a linux ec2 instance on amazon and have installed cassandra. 我在亚马逊上有一个Linux EC2实例,并安装了cassandra。 I then installed nodejs and used 然后我安装了nodejs并使用了

npm install node-cassandra-cql

to install the cassandra part of nodejs. 安装nodejs的cassandra部分。 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? 我的服务器说所有东西都安装好了,是否有一些偏好可以赶上我?

If you're getting an error stating the require is not defined, perhaps you're not running this using the node binary? 如果您收到错误消息,指出未定义require ,也许您没有使用node二进制文件运行它? 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. 我在项目的根目录中创建了一个文件index.js ,并将您上面粘贴的cassandra代码添加到了文件中。 I then executed (from that same directory): 然后执行(从同一目录):

$ node index.js 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM