Last active
October 24, 2021 13:45
-
-
Save rameshbaskar/ab8ffa2a47430d1e0e2a5ed84b5cc3de to your computer and use it in GitHub Desktop.
NodeJS query MySql database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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