Answers for "express mysql query in aync await"

SQL
3

async await mysql nodejs

const mysql = require('mysql'); // or use import if you use TS
const util = require('util');
const conn = mysql.createConnection({yourHOST/USER/PW/DB});

// node native promisify
const query = util.promisify(conn.query).bind(conn);

(async () => {
  try {
    const rows = await query('select count(*) as count from file_managed');
    console.log(rows);
  } finally {
    conn.end();
  }
})()
Posted by: Guest on November-19-2020

Code answers related to "SQL"

Browse Popular Code Answers by Language