Module export of pg-promise object derived from promise chain -


we're using hashicorp's vault store database connection credentials, constructing connection string pg-promise those. 'catch' vault details provided promise wrapper, due request callbacks vault api.

example database.js module:

const pgp = require('pg-promise')(/* options obj */);  const getdbo = () => {     return new promise( (resolve, reject) => {         vault.init().then(secrets => {         let credentials = secrets.dbuser + ':' + secrets.dbpass         let connstr = 'postgres://' + credentials + '<@endpoint/db>'         let dbo = pgp(connstr, (err) => {           reject(err)         })         resolve(dbo);     })     } module.exports = { get: getdbo } 

this being imported in multiple routes. seeing warning "warning: creating duplicate database object same connection." there better way resolve there 1 object per connection details?

creating , initializing connection pg-promise synchronous operation, per the api, there no point using promises that.

for initializing library see where should initialize pg-promise.

see also:


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -