drewla
0
Q:

js database connection

const mysql = require('mysql');

const con = mysql.createConnection({
  
  host: "localhost",
  user: "yourusername",
  password: "yourpassword"

  });

con.connect(function(err) {
  if (err) throw err;
  console.log("Connected!");
});
 
0

//put these lines in a seperate file
const mysql = require('mysql2');

const connection = mysql.createPool({
    host: "localhost",
    user: "",
    password: "",
    database: ""
    // here you can set connection limits and so on
});

module.exports = connection;

//put these on destination page
const connection = require('../util/connection');

async function getAll() {
    const sql = "SELECT * FROM tableName";
    const [rows] = await connection.promise().query(sql);
    return rows;
} 
exports.getAll = getAll;
3

New to Communities?

Join the community