如何使用app.poet()外部的req.body返回的数据

时间:2017-02-16 03:49:08

标签: javascript node.js express

我有这样的POST请求:

var urlencodedParser = bodyParser.urlencoded({ extended: false });
app.post('/readings', urlencodedParser,function(req, res){
  console.log(req.body);
  var Sensor = req.body;
  res.render('readingsChart');
});

我想在app.post()之外使用“传感器”,在另一个GET请求中,例如:

var queryString = 'SELECT Time, Reading FROM myTable WHERE Sensor = '+Sensor;

app.get('/getSQL', function(req, res) {
 connection.query(queryString, function(error, rows, fields) {
   if(error){console.log(error);}
   else{console.log('Connected');}
   // My Code
 });
});

我一直有这个错误:

var queryString = 'SELECT Time, Reading FROM '+table+' WHERE Sensor = '+Sensor;
                                                                        ^

ReferenceError: Sensor is not defined

先谢谢。

0 个答案:

没有答案