title: Node.js: how to apply util.promisify to mysql pool in its simplest way?
body: <p>I saw <a href="https://stackoverflow.com/questions/48626761/node-js-mysql-pool-connection-with-async-await">another thread</a> and and the post <a href="https://medium.com/@mhagemann/create-a-mysql-database-middleware-with-node-js-8-and-async-await-6984a09d49f4" rel="noreferrer">Create a MySQL Database Middleware with Node.js 8 and Async/Await</a>, but right now I just want to use the <code>util.promisify</code> in the most simplest and straight-forward way that I can think, applying it to mysql connection-pool. Regarding the Node.js <a href="https://nodejs.org/dist/latest-v8.x/docs/api/util.html#util_util_promisify_original" rel="noreferrer">documentation</a>, bellow is my code snipet:</p>
  
  <pre><code>exports.genAdminCfg = function (app) {
    let sql = 'SELECT * FROM nav_tree;';
  
    let pool = require('mysql').createPool({
      host: 'localhost',
      user: 'root',
      password: 'mysql',
      database: 'n4_ctrl',
      connectionLimit: 4,
      multipleStatements: true
    });
  
    /* --- Works fine without "promisify":
     pool.query(sql, function (err, rows) {
       if (err) {
         console.log(err);
         return err;
       } else {
         app.locals.adminCfg = genCfg(rows);
         app.locals.adminCfg.dbConnectionPool = pool;
       }
     });
    */
  
    /* --- Does not worke with "promisify":
       TypeError: Cannot read property 'connectionConfig' of undefined
         at Pool.query (/usr/home/zipper/node/n4.live/node_modules/mysql/lib/Pool.js:194:33)
    */
    require('util').promisify(pool.query)(sql).then(function (rows) {
      app.locals.adminCfg = genCfg(rows);
      app.locals.adminCfg.dbConnectionPool = pool;
    }, function (error) {
      console.log(error);
    });
  
  };
  </code></pre>
  
  <p>The code I commented-out works fine without <code>promisify</code>. But the similar code next to it with <code>promisify</code> does not work and shows <code>TypeError: Cannot read property 'connectionConfig' of undefined</code>. What's wrong with the code?</p>
  
  <p>node version = v8.1.4</p>