using an enviroment variable for local sequelize configuration

前端 未结 4 1065
感情败类
感情败类 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:49

    you should change config.json file to a config.js module and make sure to require the dotenv at the very top.

    require('dotenv').config(); // this is important!
    module.exports = {
    "development": {
        "username": process.env.DB_USERNAME,
        "password": process.env.DB_PASSWORD,
        "database": process.env.DB_DATABASE,
        "host": process.env.DB_HOST,
        "dialect": "mysql"
    },
    "test": {
        "username": "root",
        "password": null,
        "database": "database_test",
        "host": "127.0.0.1",
        "dialect": "mysql"
    },
    "production": {
        "username": "root",
        "password": null,
        "database": "database_production",
        "host": "127.0.0.1",
        "dialect": "mysql"
    }
    };
    

    NOTE: update your .sequelizerc file to match the new config file.

    "config": path.resolve('./config', 'config.js'),
    

提交回复
热议问题