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

**URL:** <https://forums.kodeco.com/t/sendpushes-js-i-get-typeerror-cannot-read-property-rows-of-undefined-and-connection-terminated-unexpectedly/73820>\
**Category:** Push Notifications by Tutorials\
**Created:** [June 13, 2019, 6:58pm UTC](https://forums.kodeco.com/t/sendpushes-js-i-get-typeerror-cannot-read-property-rows-of-undefined-and-connection-terminated-unexpectedly/73820 "2019-06-13T18:58:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![a-elnajjar](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/a-elnajjar/32/105896_2.png) [@a-elnajjar](https://forums.kodeco.com/u/a-elnajjar)\
**Post date:** [June 13, 2019, 6:58pm UTC](https://forums.kodeco.com/t/sendpushes-js-i-get-typeerror-cannot-read-property-rows-of-undefined-and-connection-terminated-unexpectedly/73820/1 "2019-06-13T18:58:47Z")

</div>

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)  
> and  
> 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)

code

```
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 = res.rows.map(row => row.token)

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

```

---

<div class="post-metadata">

**Author:** ![gargoyle](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/gargoyle/32/107285_2.png) [@gargoyle](https://forums.kodeco.com/u/gargoyle)\
**Post date:** [June 14, 2019, 3:24am UTC](https://forums.kodeco.com/t/sendpushes-js-i-get-typeerror-cannot-read-property-rows-of-undefined-and-connection-terminated-unexpectedly/73820/2 "2019-06-14T03:24:29Z")

</div>

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.
