title: express.js app knex.js async connection with aws secrets manager call is firing out of order
body: <p>I've been stuck on this for days, it feels like no matter how I structure it, the aws secret manager call ALWAYS returns after the app gets initialized. npm run start fires app.js file, this triggers knex and everything runs in order but the secrets response with the username/password seems to come back after everything's already initialized.</p>
  <p>knex.js:</p>
  <pre><code>console.log(&quot;knex.js&quot;)
  const environment = process.env.APP_ENV || 'development'
  const config = require('../knexfile.js')[environment];
  const knex = require('knex')(config);
  
  module.exports = knex
  </code></pre>
  <p>knexfile.js:</p>
  <pre><code>require('dotenv').config();
  const path = require('path')
  const pathToCert = path.resolve(__dirname, 'root.cert'); // where to save a file
  
  console.log(&quot;knexfile.js&quot;)
  
  var AWS = require('aws-sdk');
  region = 'us-east-2'
  secretName = 'blah'
  var client = new AWS.SecretsManager({
    region: region
  });
  async function getConfig() {
    console.log(&quot;in get config&quot;)
    return await new Promise((resolve, reject) =&gt; {
      client.getSecretValue({ SecretId: secretName }, function (
        err,
        data
      ) {
        let secret = JSON.parse(data.SecretString);
        console.log(&quot;returning it***************&quot; + secret.password + &quot; &quot; + secret.username + &quot; &quot; + pathToCert)
        let connectionString = `postgresql://${secret.username}:${secret.password}@some-host:1234/defaultdb?sslmode=verify-full&amp;sslrootcert=${pathToCert}&amp;options=--cluster`
        resolve(connectionString)
        return
  
      })
    })
  }
  const config = {
    development: {
      client: 'pg',
      version: 7.2,
      connection: getConfig(),
      migrations: {
        directory: './knex/migrations',
      },
      seeds: {
        directory: './knex/seeds'
      }
    }
  
  }
  console.log(&quot;exporting module&quot;)
  module.exports = config
  </code></pre>
  <p>The console returns:</p>
  <pre><code>knex.js
  knexfile.js
  in get config
  exporting module
  Listening on: 3000
  returning it***************pass username C:\project-webservice\root.cert
  </code></pre>
  <p>Does anyone see what I'm doing wrong?</p>