using an enviroment variable for local sequelize configuration

前端 未结 4 1053
感情败类
感情败类 2021-02-04 07:25

I\'m looking to use an environment variable inside of the config.json file of my project using sequelize. I\'m using dotenv to set environment variables locally. My config.json

4条回答
  •  独厮守ぢ
    2021-02-04 07:39

    I worked on this for quite a bit. I do not know why Sequelize does not use production when it is literally in the environment if you run heroku run bash. I was able to get it working by modifying the Sequelize object depending on the JAWSDB_URL, not the NODE_ENV.

    require("dotenv").config();
    const express = require("express")
    const app = express();
    let seq;
    
    //express app configuration
    
    if (process.env.JAWSDB_URL) {
        console.log("There is a JAWS DB URL")
        seq = new Sequelize(process.env.JAWSDB_URL)
    }
    else {
        seq = require("./models").sequelize
    }
    seq.sync().then(() => {
      app.listen(PORT, () => console.log('server started on port ' + PORT));
    })
    

提交回复
热议问题