I'm using Node.js
and npm mysql. How can I 'get rid' of return new Promise
here and replace it with async await
syntax?
const config = require('config');
const mysql = require('mysql');
class DatabaseConnection {
static connect(logger) {
return new Promise(((resolve, reject) => {
const con = mysql.createConnection({
host: config.db.host,
user: config.db.user,
password: config.db.password,
database: config.db.db,
});
con.connect((err) => {
if (err) {
reject(err);
}
else {
logger.debug('Connected!');
resolve(con);
}
});
}));
}
}
module.exports = DatabaseConnection;