Skip to content

Instantly share code, notes, and snippets.

@rameshbaskar
Last active October 24, 2021 13:45
Show Gist options
  • Save rameshbaskar/ab8ffa2a47430d1e0e2a5ed84b5cc3de to your computer and use it in GitHub Desktop.
Save rameshbaskar/ab8ffa2a47430d1e0e2a5ed84b5cc3de to your computer and use it in GitHub Desktop.
NodeJS query MySql database
import mysql from 'mysql';
const {
DB_HOST,
DB_USER,
DB_PASSWORD,
DB_NAME
} = process.env
export const database = mysql.createPool({
connectionLimit: 10,
host: DB_HOST,
user: DB_USER,
password: DB_PASSWORD,
database: DB_NAME,
ssl: true
});
export const queryDatabase = async (sql) => {
return new Promise((resolve, reject) => {
database.query(sql, (error, results) => {
if (error) reject(error);
resolve(results);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment