0

I'm adding a pagination in my product list. But I kept having error:

console.log(data.rows);
                   ^

Here's my js file that's query-ing in my database:

list: (client, filter, callback) => {
const productListQuery = `
SELECT * 
FROM products 
ORDER BY id
`;
client.query(productListQuery, (req, result)=>{
  console.log(result.rows);
  callback(result.rows);
});

Here's my router.get in my server.js:

app.get('/products', function (req, res, next) {
  Product.list(client, {limit: 8}, {offset: (req.query.p - 1) * 8}, {
  }, function (products) {
    res.render('/client/product-list', {
      products: products,
      title: 'Products',
      pagination: {
        page: req.query.p || 1,
        limit: 8,
        n: req.query.p || 1
      }
    });
  });
});
2
  • 1
    Please add your code :) Commented Oct 1, 2018 at 17:15
  • Please add your code as content to the question, not as image links. Commented Oct 1, 2018 at 18:13

1 Answer 1

2

That just simply means your data is undefined and in JavaScript undefined objects don't have any property or value.

Would recommend you to go though JavaScript Documentation before using it.

When you called your database, there was an error in response and since you didn't handled response correctly thus getting this error.

To understand different between undefined and other object values:

let a;
let b = 22;
let c = null;
let d = {
    'a': 22,
    'b': [4,5,6]
};

console.log(a);  // undefined
console.log(a.b);  // TypeError: Cannot read property 'b' of undefined
console.log(b);  // 22
console.log(b.c);  // undefined
console.log(c);  // null
console.log(d.a);  // 22
console.log(d.b);  // [4,5,6]
console.log(e);  // ReferenceError: e is not defined
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.