Group Group Group Group Group Group Group Group Group

sendPushes.js I get TypeError: Cannot read property 'rows' of undefined and Connection terminated unexpectedly

I have installed nodejs to run and test sendPushes.js but I have a problem is not connected and I get this error stack. also I ran the script in VS code

TypeError: Cannot read property ‘rows’ of undefined
at Query.callback (/Users/abdalla.mohamed/Documents/SandBox/PushNotifications/Sources/Appjs/main.js:40:22)
at Query.handleError (/Users/user/node_modules/pg/lib/query.js:142:17)
at /Users/user/node_modules/pg/lib/client.js:63:13
at processTicksAndRejections (internal/process/task_queues.js:82:9)
Error: Connection terminated unexpectedly
at Connection. (/Users/user/node_modules/pg/lib/client.js:235:9)
at Object.onceWrapper (events.js:288:20)
at Connection.emit (events.js:200:13)
at Socket. (/Users/user/node_modules/pg/lib/connection.js:77:10)
at Socket.emit (events.js:200:13)
at TCP. (net.js:586:12)


client.query('SELECT DISTINCT token FROM tokens WHERE debug = true', (err, res) => {
  console.log("error"+ err ? err.stack : res.rows[0].message) 

  console.log(err ? err.stack : res.rows[0].message) 

  const tokens = => row.token)

  apnProvider.send(note, tokens).then( (response) => {
     if(response.sent == true)//has successful pushes
     else if (response.failed == true)
    // response.failed has error details

Unfortunately I’m not a node expert, but looking at your error it would appear that res variable isn’t being set, and so you don’t have any rows available. Sounds like you’re having an issue talking to your SQL server from the node script.