0

basically, i am trying to make my app choose which database it's going to use. i'm having trouble, because i keep getting a "TypeError: Cannot read properties of undefined (reading 'max')". i've spent about three hours on this (very new to web stack stuff, so don't laugh at me please) and could really use some assistance. thanks in advance.

db.config.js.

it doesn't work with pool active either, so don't mind that.

require('dotenv').config();


module.exports = {
  dev: {
    HOST: "localhost",
    USER: "postgres",
    PASSWORD: "redacted",
    DB: "testtest",
    //dialect: "mysql"
    dialect: "postgres"
  }, // pool was here, removed it to make the whole thing smaller 
  production:{
    // empty until i get actual production values from my hosting service 
  }
}

index.js

const env = process.env.NODE_ENV || 'dev';
const config = require("../config/db.config.js");

const Sequelize = require("sequelize");
const sequelize = new Sequelize(
  config.DB,
  config.USER,
  config.PASSWORD,
  {
    host: config.HOST,
    dialect: config.dialect,
    operatorsAliases: false,

    pool: {
      // omitted to make example smaller 
    }
  }
);

const db = {};

db.Sequelize = Sequelize;
db.sequelize = sequelize;

// ...models relationships defined here 

module.exports = db;

to my understanding,

const env = process.env.NODE_ENV || 'dev';

means that if a value isn't present within my .env file (it isn't), it will default to 'dev' settings, and connect to my local database.

const config = require("../config/db.config.js");

this is here so the file can access those values.

i tried making an entirely separate file for environment configuration, but it gave me a sequelize error (that i can't pull up right now). this is what i had before:

const dbEngine = process.env.DB_ENVIRONMENT || 'dev';
const config = require('./db.config')[dbEngine];

module.exports = require('sequelize')(config);
joey
  • 1
  • 1
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community Dec 28 '22 at 08:56
  • Bumping this! I'm trying to move on to other features; this is still stymieing me. – joey Dec 28 '22 at 21:29

0 Answers0