I am trying to deploy a node/express backend on Netlify. I have a PostgreSQL database hosted on my local machine.
When I test the app in my local environment (i.e. on localhost using npm start run) I am able to load all routes and access data as expected. However when I try to access it via the live website I get this error:
If I visit URLs that point to routes that do not require connection to the PostgreSQL database, they work fine - i.e https://todos-back.netlify.app/api.
I am using the node-postgres package to manage connections to my database.
Here are the postgres database details (with user and password redacted for security purposes):
DB_USER={myusername}
DB_PW ={mypassword}
DB_HOST=‘localhost’
DB_PORT=‘5432’
DB_DATABASE=‘todos’
Here is the information on the postgres connection coming from pgAdmin 4
Yes, the Postgres database is on my local machine. So your answer makes sense to me
Is there any way to allow the app to access the database on my local machine? Or would I need to host the database on a server somewhere? For example, I’ve built a database on ElephantSQL before, would having my node-postgres client connect to that be better?
This is my first time deploying a backend so some of the concepts are a little challenging for me - any insight greatly appreciated!
You would need to set the connection details to the IP address of your computer and ensure the connection is allowed through any firewalls that might be in place.
Hosting it yourself is fine for development, but it’s not something that I’d do for production anyway, and I’d assumed that you’d run into connection issues.
I guess this leads to another question - say I wanted to keep my backend app hosted on Netlify. I could keep my app basically the same, but instead of pointing to localhost in my node-postgres configuration, I would point to the supabase address instead?