Friday, 12 May 2017

Value not updating in PostgreSQL using NodeJs

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

var pg = require('pg');

var connectionString  = "postgresql://postgres:sujay123@localhost:3001/redc";



app.use(express.static('public'));  

app.get('/index.html', function (req, res) {  
   res.sendFile( __dirname + "/" + "index.html" );  
})  
app.get('/process_get', function (req, res) {  
response = {  
       name:req.query.name,  
       lat:req.query.lat,
       long1:req.query.long  
   };  
   console.log(response);  

   res.end(JSON.stringify(response));  

     var client = new pg.Client(connectionString);
     client.connect();
     console.log("connect");

     console.log("INSERT INTO data(name, latitude,longitude) values('"+req.query.name+"',"+req.query.lat+","+req.query.long+")");
     var i = client.query("INSERT INTO data values('"+req.query.name+"',"+req.query.lat+","+req.query.long+")");
     console.log(i);
     console.log("Query Inserted")
})  
var server = app.listen(3001, function () {  

  var host = server.address().address  
  var port = server.address().port  
  console.log("Example app listening at http://%s:%s", host, port)  

})  

I am getting this code and running but when i check the db the insert query has not worked and th values in the 3 paramters are coming of name, lat and long just the query isnt working i guess.



via Sujay Venaik

No comments:

Post a Comment