How to link node.js app and postgresql?

I have a node.js application that builds successfully.

i want to link it with postresql which i posted also on render.io

here are my settings for the postgres (this is a study project, so I don’t worry about posting this data):


here are my settings for the .env file:

PORT=3001

### RENDER
DB=todo_qjbn
HOST=postgres://chaosmos:HHuIdSHUQjWhoO7iCAxWnhYjO0ROULN2@dpg-cf602gla499d72tdg4mg-a.frankfurt-postgres.render.com/todo_qjbn
#POSTGRESQLHOST=dpg-cf602gla499d72tdg4mg-a
PASSWORD=HHuIdSHUQjWhoO7iCAxWnhYjO0ROULN2
PORT=5432
USER=chaosmos

here is my postgres connection settings in code:

export const AppDataSource = new DataSource({
  type: 'postgres',
  host: process.env.HOST,
  port: process.env.PORT,
  username: process.env.USER,
  password: process.env.PASSWORD,
  database: process.env.DB,
  entities: [Task],
  synchronize: false,
});

const port = process.env.PORT;

AppDataSource
  .initialize()
  .then(() => {
    app.listen(port);
    console.log('Data Source has been initialized');
  })
  .catch((err) => {
    console.error('Error!!! during Data Source initialization', err);
  });

app.use('/', tasksRouter);

When I build I get this error:

Apparently, something is wrong with the database connection settings
what is the problem and how can i fix this error?

Could someone clarify one more question for me - can I place here on render.com at the same time a site on react.js + a backend on node.js (which I described above)?

now I’m trying to link the frontend to react.js, which I posted on vercel.com and the backend to node.js + postgres

can i place both frontend and backend here at the same time? if yes, how do i do it?

Hi,

You’ve shared all the credentials for your database, so I would suggest deleting that instance and creating a new one if you haven’t done so already. Never share passwords with anyone and especially not on a public forum.

The logs screenshot shows you’ve used the full connection string as a “hostname”, which would be invalid. You can see how the connection string breakdown into host/user/password/etc in the docs.

If you’re connecting from another Render service in the same account & region, use the Internal Database URL. And then refer to the documentation of the database package you’re using to see how to configure it. Most will take the connection string URL.

Alan

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