nodejs--express的使用,並與cassandra的鏈接

node app.js前端

app.jsnode

var express = require("express");
var app = express();

app.use(express.static(__dirname + '/app'));
app.use(express.bodyParser());
app.use(express.methodOverride());
var cql = require('node-cassandra-cql');
var uuid = require('./node-uuid');
var connString = {
    hosts: ['xxx'],
    keyspace: 'xxx',
    username:'xxx',
    password:'xxx'
}
var client = new cql.Client(connString);
     client.connect(function(error){    
        if(error)
            console.log('error - ' + error);
        else
            console.log('Post Logged In to Cassandra');
         });

從數據庫中抽取數據發送到前端:數據庫

app.get('/objValuesResult/:key',function(req,res){
     console.log('get2 objValues');
      console.log('get2 objValues'+'/:'+req.params.key);
      client.executeAsPrepared('select * from table ', 
          [req.params.key], cql.types.consistencies.one,
         function(err, result) {
            if(err){
                console.log(err);
                res.send('Sorry error');
                res.end();
                }else{
                           res.send(result.rows);          
                            res.end();     

            }
    });
相關文章
相關標籤/搜索