samedi 11 janvier 2020

Conditionally Assign const value in js

I'm trying to assign a different value to sequelize based on whether the app is running locally or on the server. This is my code:

    const sequelize = production
  ? sequelizeHeroku.connect(Sequelize)
  : new Sequelize(database, user, password, {
      host,
      dialect: "mysql",
      pool: {
        max: 10,
        min: 0,
        acquire: 30000,
        idle: 10000
      }
    });

This doesn't work locally, as when I log the value of sequelize it is false. However, if I try to assign the variable like this:

const sequelize = new Sequelize(database, user, password, {
  host,
  dialect: "mysql",
  pool: {
    max: 10,
    min: 0,
    acquire: 30000,
    idle: 10000
  }
});

it works just fine. I also checked that console.log(production == true) prints out false. What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire