How do I check with nodejs, if a table is unregistered?

2

Well, I want to check a table with nodejs to see if it has no records.

How can I do this so that it does not give error with nodejs?

Thank you.

    
asked by anonymous 30.03.2017 / 06:53

1 answer

2

Check the .length of the result:

db.query('SELECT * from tabela', (err, res) => {
    console.log(err, res, res.length); // deve dar null, [], 0
    if (res.length == 0){
        console.log('A tabela está vazia!');
    }
});
    
30.03.2017 / 07:22