Skip to content

Instantly share code, notes, and snippets.

@Erushenko
Created February 13, 2019 15:24
Show Gist options
  • Save Erushenko/8fb492df3d598fcc7fefd362a9bfef2c to your computer and use it in GitHub Desktop.
Save Erushenko/8fb492df3d598fcc7fefd362a9bfef2c to your computer and use it in GitHub Desktop.
get and use connection string from env
module.exports = {
jwt: env('JWT_SECRET'),
pg: {
connection: `postgres://app:${env('PG_APP_PWD', 'app')}@${env('PG_HOST', 'localhost')}/db`,
client: 'pg',
},
pgTwo: {
connection: `postgres://app2:${env('PG_APP2_PWD', 'APP2')}@${env('PG_APP2_HOST', 'localhost:port')}/db2`,
client: 'pg',
},
queue: `amqp://app:${env('RMQ_APP_PWD', 'app')}@${env('RMQ_HOST', 'localhost')}/app`,
}
function env (key, defaultValue) {
const value = process.env[key] || defaultValue
if (!value) {
throw new Error(`process.env.${key} is missing!`)
}
return value
}
const config = require('./config')
const knex = require('knex')(config.pg)
module.exports = knex
const pg = require('./pg')
const getUserUpdateAt = pg('Users')
.where({ id: user.id })
.first()
.then(it => _.get(it,'updated_at'))
//continue...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment