So I want to build a website that queries data from a MySQL database. I installed the mysql package in Node.js (command: npm install mysql).
On my local machine it works but it doesn't in the browser which I understand because the package is only installed locally.
I now want to know how I can use this NPM package in a browser and still use the require() method for my database.
Code (if needed):
const mysql = require("mysql");
const connection = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "test"
});
connection.connect((err) => {
if (err) {
console.log("connection = false; error: " + err);
} else {
console.log("connection = true");
}
});
connection.query("SELECT * FROM databasetest", (err, response) => {
for (let i = 0; i < response.length; i++) {
console.log(response[i]);
}
});
Thanks!