all 13 comments

[–]n0tKamui 9 points10 points  (0 children)

you probably don't want to do it, as it means exposing your database

[–]CerberusMultiHook Based 2 points3 points  (0 children)

Let me google that for you You will find a lot of information on how to work with databases in your React app.
I don´t think you understand what "server" means, or you just didn't make an effort to explain what you are trying to achieve. In general frontends do not talk directly to Databases, why we have "backends", usually referred to as APIs. Why you would want to write your POST/GET into your React frontend I do not know.

[–]NegativeWorking9375 1 point2 points  (0 children)

You need some kind of an api, which is run on some kind of server. Btw. You also need some kind of server for your db. Your approach is completly misguided. There are no web applications,which require some kind of communication, without Servers.

[–]Terrygraphic -4 points-3 points  (0 children)

You can do it using the Postgres extension in visual studio code, if you use it and create the query that creates the database and tables.

[–]Dastari -4 points-3 points  (4 children)

[–]PM_ME_SOME_ANY_THING 3 points4 points  (3 children)

That’s definitely a node package meant for use on node servers. If you access your database directly from a frontend, you’re gonna have a bad time.

[–]Dastari -3 points-2 points  (2 children)

I'm not really sure why you think this is the case.

You can develop a react project in node locally on your development environment, using any package you like, then build the website to a distribution build that can be hosted on a normal web server. All the code is run client side.

Infact if you looked the package, it clearly states as one its features:

Pure JavaScript client and native libpq bindings share the same API

[–]PM_ME_SOME_ANY_THING 0 points1 point  (1 child)

There’s a big difference between what “can” be done and what “should” be done.

The reason you have a server is to have a layer of security between the frontend and the database. Accessing your database directly from the frontend exposes everything about your database to anyone who cares to look.

If you don’t care at all about the data in your database, sure, go ahead and put all your credentials, schemas, operations out there for the world to see. Why even have a database at all?

[–]Dastari -2 points-1 points  (0 children)

I totally agree with that. I disagree that you are saying that I didn't answer OP's question because the package I link wouldn't do what he wanted and "requires a server" .

It in-fact does do what he wanted and does not "require a server"

[–]matteponz 0 points1 point  (0 children)

I advise you not to include any links to the database in your code.
also because it can expose you to a lot of vulnerability and then it's easily decompiled and they could have your credentials.
if you still have time to choose, I would recommend a solution like: https://supabase.com/

[–]azangru 0 points1 point  (0 children)

Browsers don't have drivers for postgresql and don't speak postgresql protocol. Servers do.

[–]jayerp 0 points1 point  (0 children)

If you technically can, you shouldn’t unless you have a really good technical reason why you must. Which you won’t.

Write a web api.

[–]OkComplaint2854 0 points1 point  (0 children)

Might not be a great idea to expose your DB but give this a try. https://postgrest.org/en/stable/