const mysql = require("mysql");
const db = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "dbname",
charset: "utf8mb4_bin"
});
db.connect(err => {
if(err) throw err;
});
module.exports = db;
const mysql = require("mysql");
const mysqlDb = mysql.createConnection({
host: process.env.mysql_HOST || "localhost",
user: process.env.mysql_USER || "root",
password: process.env.mysql_PASSWORD || "",
database: process.env.mysql_DATABSE || "my_db"
});
mysqlDb.connect(err => {
if(err) throw err;
});
module.exports = mysqlDb;
git clone https://github.com/LloydJanseVanRensburg/Node-Express-starter.git
// you can't connect to mysql in client side js
// but you can use it in nodejs which is server-side
// for nodejs you can use package named mysql2
npm i mysql2
// read Doc here
// https://www.npmjs.com/package/mysql2