Created
February 13, 2019 15:24
-
-
Save Erushenko/8fb492df3d598fcc7fefd362a9bfef2c to your computer and use it in GitHub Desktop.
get and use connection string from env
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const config = require('./config') | |
const knex = require('knex')(config.pg) | |
module.exports = knex |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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