Nodejs传入url的结束点

nodejs passing in the end point of the url

本文关键字:结束 url 传入 Nodejs      更新时间:2023-09-26

我想创建一个简单的js应用程序来查询cassandra数据库,像这样:

var express = require('express');
var cassandra = require('cassandra-driver')
var app = express();
var client = new cassandra.Client({contactPoints: ['127.0.0.1'], keyspace: 'custprd'});
app.get('/', function (req, res) {
  res.send('Hello Ronak!');
});
app.get('/customer/:ent_cust_id', function (req, res, next) {
        var query = 'Select * from entcustinfo where ent_cust_id = ?';
        consolelog('Select * from entcustinfo where ent_cust_id = ?');
        client.execute(query, [req.params.ent_cust_id], function (err, result) {
    if (err) return next (err);
    var row = result.rows[0];
    //Response
    res.json({ent_cust_id: req.params.ent_cust_id, name: row.get('offers')});
});
});

var server = app.listen(3030, function () {
  var host = server.address().address;
  var port = server.address().port;
  console.log('Example app listening at http://%s:%s', host, port);
});

现在,当我在浏览器中输入call http://10.205.116.141:3030/customer/1013686356时,我得到了这个:

Error: Expected 4 or 0 byte int (10)

和控制台日志显示如下:

Select * from entcustinfo where ent_cust_id = ?

我认为?是传递url结束点的方式?

编辑:

我认为这与execute和executeAsPrepared有关…我使用executeAsPrepare,我得到这个错误:TypeError: undefined is not a function

我是这样让它工作的:

app.get('/customer/:ent_cust_id', function (req, res, next) {
        var query = 'Select * from entcustinfo where ent_cust_id = ?' [req.params.ent_cust_id];
        consolelog('Select * from entcustinfo where ent_cust_id = ?');
        client.execute(query, function (err, result) {
    if (err) return next (err);
    var row = result.rows[0];
    //Response
    res.json({ent_cust_id: req.params.ent_cust_id, name: row.get('offers')});
});
});

我把[req.params.ent_cust_id]移到var query