Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
Async await problem in nodejs sequelize connection string

function credential(secretFromVault) {
  const creddetails = new ClientSecretCredential(clientId, tenantId, cleintSecret);
  // Build the URL to reach your key vault
  const url = `https://<vaultName>.vault.azure.net/`;

  // Lastly, create our secrets client and connect to the service
  const client = new SecretClient(url, creddetails);

  const secretName = secretFromVault;
  return new Promise(resolve => {
    client.getSecret(secretName).then(latestSecret => {
      console.log(`value from secret is`, latestSecret.value);
      resolve(latestSecret.value)
    })
  })
}
const dbUserName = credential(constants.pgDbUserName)
const dbPassword = credential(constants.pgDbPassword)

const hostname = constants.pgHostname;
const port = constants.pgPort;
const dbName = constants.pgDbName;
const sequelize = new Sequelize(dbName, dbUserName, dbPassword, {
  host: hostname,
  port: port,
  dialect: constants.dialectName,
  logging: false,
  pool: {
    max: constants.pgMaxPoolConnections,
    min: constants.pgMinPoolConnections,
    acquire: constants.pgMakeConnectionTimeOut,
    idle: constants.pgIdleTimeout
  }
});
sequelize.authenticate()
  .then(() => {
    console.log('Successfully connected.');
    User.sync();
    Credentials.sync();
    App.sync();
    Entity.sync();
    EntityField.sync();
    Relationship.sync();
  })
  .catch(err => console.log('Error: ' + err))

I am using the above code to make connection to postgres database. But I am receiving below error on execution of node index command, index.js is not attached here. I want dbUSerName and dbUserpassword values to be passed in the sequelize connection string after fetched from the vault. but the values are promise which I am not able to resolve.

error: uncaughtException: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of Promise

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

credential function returns Promise, you need to call it as a promise function.

You can read about promises here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

I think it will be better to wrap your code in a async function and use await before calling credential


async function main() {
    const dbUserName = await credential(constants.pgDbUserName);
    const dbPassword = await credential(constants.pgDbPassword);
 
    // Your code
}

main();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!