Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbConnection code quality changes #50

Open
finnhodgkin opened this issue Jan 14, 2018 · 0 comments
Open

dbConnection code quality changes #50

finnhodgkin opened this issue Jan 14, 2018 · 0 comments

Comments

@finnhodgkin
Copy link

Nothing major so feel free to ignore, but I prefer ternary assignment with const to if statements with let:

const DB_URL =
  process.env.NODE_ENV === 'test'
    ? process.env.DATABASE_URL
    : process.env.DB_URLTEST;

vs

let DB_URL = process.env.DATABASE_URL;
if (process.env.NODE_ENV === 'test') {
  DB_URL = process.env.DB_URLTEST;
}

I also prefer the simplicity of connectionString over manual configuration for dbConnection.js:

const { Pool } = require('pg');
const environment = require('env2')('.env');

const DB_URL =
  process.env.NODE_ENV === 'test'
    ? process.env.DATABASE_URL
    : process.env.DB_URLTEST;

if (!DB_URL) {
  throw new Error('Environment variable DATABASE_URL must be set');
}

const pool = new Pool({
  connectionString: DB_URL,
});

module.exports = pool;

Then in the config.env extra options like max and ssl can be supplied through query parameters at the end of the url:

postgres://user:password@localhost:5432/databasee?ssl=1&max=18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant