Search code examples
node.jsreactjsdatabaseserverweb-development-server

Is it Possible to connect to a database that is on Heroku From React directly


Is it possible to connect to a database hosted on Heroku with my react app?

If so, can I make queries directly with the react app codes, or should I first connect to the database on the server-side with node.js; and then get information to the react app via that node program I made to communicate with the database?


Solution

  • Communication with the database should be done at the server-side not in the front-end app because this action has security and anti-pattern/bad practice problems + less management on the dataflow of your database.

    Imagine that, there is no WAF (web application firewall) or any middleware on the server-side to check the correctness of the requests and the inputs and just react app manages the SQL queries... In this case, anyone can change or dump the entire database by changing the requests. It's a pure SQL injection vulnerability.