# Heroku Postgresql in Node-Red

**URL:** <https://discourse.nodered.org/t/heroku-postgresql-in-node-red/79566>\
**Category:** General\
**Tags:** database\
**Created:** [3 July 2023 22:03 UTC](https://discourse.nodered.org/t/heroku-postgresql-in-node-red/79566 "2023-07-03T22:03:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Azbbo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/azbbo/32/81090_2.png) [@Azbbo](https://discourse.nodered.org/u/Azbbo)\
**Post date:** [3 July 2023 22:03 UTC](https://discourse.nodered.org/t/heroku-postgresql-in-node-red/79566/1 "2023-07-03T22:03:32Z")

</div>

Hello! Im new to Node-RED and Databases,  
Windows 11  
Node v18.16.1  
npm v9.5.1  
Node-red v3.0.2  
i have an app on Heroku with Postgresql add-on and im trying to connect to it via Node-RED to send data to a table, Query, etc., Node-RED is installed on my laptop, running on 127.0.0.1:1880, when trying to connect a node to Postgres i get "Error: Self signed certificate" when i disable ssl i get something like

"error: no pg\_hba.conf entry for host "192.168.1.1", (Example IP)  
user "XXXXXX",  
database "XXXXX", no encryption"

When trying to create that entry i found it dificult through the Heroku CLI to even get to the file, and once i was there, i couldn edit it (Not 100% sure)

Then read that i could make a new user and give it an ip to access, tried it but then realized Heroku Postgres doesnt let you create new users (Not 100% sure, like 95%)

Finally tried to use chat gpt to solve the problem but it gave me some suggestions that werent possible for me like:

```auto
 httpServerOptions: {
    https: { rejectUnauthorized: false }
  },

```

Checked ServerOptions documentation for its options and rejectUnauthorized isnt one of them

Spent days searching what could it be, tried a clean installation, nothing so im completely lost, i would really apreciate it if anyone could give me any tips to solve this problem

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [4 July 2023 07:11 UTC](https://discourse.nodered.org/t/heroku-postgresql-in-node-red/79566/2 "2023-07-04T07:11:13Z")

</div>

Welcome to the forum @Azbbo

I am confused, are you trying to connect to a database on a heroku server from node red running on your laptop?

---

<div class="post-metadata">

**Author:** ![Azbbo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/azbbo/32/81090_2.png) [@Azbbo](https://discourse.nodered.org/u/Azbbo)\
**Post date:** [4 July 2023 14:20 UTC](https://discourse.nodered.org/t/heroku-postgresql-in-node-red/79566/3 "2023-07-04T14:20:07Z")

</div>

Yeah, Node-RED is running on my PC, and the database is on the server

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [4 July 2023 14:52 UTC](https://discourse.nodered.org/t/heroku-postgresql-in-node-red/79566/4 "2023-07-04T14:52:51Z")

</div>

Are you able to access the db using different SQL client software?

---

<div class="post-metadata">

**Author:** ![Azbbo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/azbbo/32/81090_2.png) [@Azbbo](https://discourse.nodered.org/u/Azbbo)\
**Post date:** [4 July 2023 15:06 UTC](https://discourse.nodered.org/t/heroku-postgresql-in-node-red/79566/5 "2023-07-04T15:06:57Z")

</div>

Yes, i have python code that connects to it every 10 min and adds data, pgAdmin and Table Plus

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 July 2023 10:58 UTC](https://discourse.nodered.org/t/heroku-postgresql-in-node-red/79566/6 "2023-07-05T10:58:57Z")

</div>

What settings are you using in Python? I am confused that in the error you post it shows a local IP address rather than an external one.

---

<div class="post-metadata">

**Author:** ![Azbbo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/azbbo/32/81090_2.png) [@Azbbo](https://discourse.nodered.org/u/Azbbo)\
**Post date:** [5 July 2023 14:58 UTC](https://discourse.nodered.org/t/heroku-postgresql-in-node-red/79566/7 "2023-07-05T14:58:56Z")

</div>

the ip was an example to not show the public IP, sorry for the confusion, both through python and pgadmin/tableplus i can connect without a problem, make changes, read data and all

When trying to connect with Node-RED i get "Error: self-signed certificate", turning off SSL from the postgres node gets me

"error: no pg\_hba.conf entry for host "182.xxx.xxx.xxx", (Example IP)  
user "XXXXXX",  
database "XXXXX", no encryption"

which is my public ip

Created a ticket to Heroku support to see if they could help me with this error and they provided the following code

const client= new Client({  
connectionString: process.env.DATABASE\_URL,  
ssl:{  
rejectUnauthorized: false  
}  
});

This is for Node.js, so i need to have a similar configuration for Node-RED, so i changed the setting.js to:

const { Client } = require('pg');

const client = new Client({  
ssl: {  
rejectUnauthorized: false  
}  
});

module.exports = {

and

functionGlobalContext: {  
// os:require('os'),  
client  
},

didnt worked, im not sure how to add the code Heroku Support gave me to the settings.js for Node-RED to see if it works

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 September 2023 14:59 UTC](https://discourse.nodered.org/t/heroku-postgresql-in-node-red/79566/8 "2023-09-03T14:59:14Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
