Skip to content

Instantly share code, notes, and snippets.

@aqkhan
Created September 1, 2021 10:59
Show Gist options
  • Save aqkhan/d2691c393d95b768acebce11d1169b07 to your computer and use it in GitHub Desktop.
Save aqkhan/d2691c393d95b768acebce11d1169b07 to your computer and use it in GitHub Desktop.
const mysql = require("mysql");
const dotenv = require("dotenv");
dotenv.config();
// Create a connection to the database
const connection = mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
});
// open the MySQL connection
connection.connect((error) => {
if (error) throw error;
console.log("Successfully connected to the database.");
});
module.exports = connection;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment