Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

184
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda