Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to display some users from a postgres db that I have set up, but I am running into a little trouble. The users are not displaying onto the console when I try to display them.

I have an index.js where I have this function:

function list(callback) {
 var client = new pg.Client(cstr);
 var query = client.query('SELECT name FROM users');
    query.on('row', function(row) {
      console.log('user "%s"', row.name);
    });
}

Now I try calling this in my app.js in one of my route handlers:

app.get('/users', function (req, res) {
  db.list(function(data){
    console.log(data); 
  }); 
});

Now I am relatively new to both node and postgres so there may be a few contributing factors to this issue.

I am still trying to wrap my head around the callback and how it works, so I am not sure I am using it correctly in my list function. But I am trying to just take names from a db table called users. Nothing is giving me an error, but the names just are not appearing.

I've tried looking at some posts on stack and online, but nothing has helped me so far.

Is there anything that I am overlooking, or that I should consider taking a second look at?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.