Skip to content

dbConnection code quality changes #50

@finnhodgkin

Description

@finnhodgkin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions