How to make a query in the database with Javascript? [duplicate]

-2

I would like to know how to do a select in a table in the database with javascript

    
asked by anonymous 30.08.2018 / 22:09

1 answer

1

Your question is a little broad, but come on, it's a perfectly valid question for a beginner.

It is not the language that accesses the database, it is some library or framework made for that language. Some languages have access to some database types in the standard library, some not.

In the case of Javascript, it will always be necessary to install a third-party library to access any database.

In Javascript there is an additional complicator: the environment in which it runs. The two most common environments are browser and Node.js. As far as I know every library for bank access is made to the Node.js. environment. You will install via NPM.

The browser environment is much more restricted, I think nor does it offer the conditions for such a library. For example: to access a MySQL database you need to make a TCP / IP connection, but in the browser this is forbidden due to security issues.

But let's say your need is for an application running on the browser to have access to the database. You will have to do this in an indirect way, with the browser doing REST, GraphQL or other requests to a Web server, and doing this query to a database.

It is not recommended at all to pass SQL queries directly from the browser to the server using this brokerage scheme, because any attacker could then send "bad" DROP DATABASE SQL queries.

    
30.08.2018 / 22:45