5

I am trying to run a db migration with the Sequelize CLI tool, but I'm running into an issue where my ENV variables are not being processed by the tool. In the github repo, it says in version 2.0.0 (I'm on 2.4.0) you can directly access ENV variables in config/config.js like so, process.env.DB_HOSTNAME, but I get an error that indicates that no values are being passed in from the variables

Error:

Unable to connect to database: SequelizeAccessDeniedError: ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: NO)

config.js:

module.exports = {
    "development": {
        "username": process.env.LOCAL_USERNAME,
        "password": process.env.LOCAL_PASSWORD,
        "database": process.env.LOCAL_DATABASE,
        "host": "127.0.0.1",
        "dialect": "mysql",
        "migrationStorageTableName": "sequelize_meta"
    },
}

.env:

LOCAL_DATABASE="db_name"
LOCAL_USERNAME="root"
LOCAL_PASSWORD="test"
cphill
  • 5,596
  • 16
  • 89
  • 182

1 Answers1

17

you forgot to require dotenv module:

require('dotenv').config();  // this line is important!
module.exports = {
"development": {
    "username": process.env.LOCAL_USERNAME,
    "password": process.env.LOCAL_PASSWORD,
    "database": process.env.LOCAL_DATABASE,
    "host": "127.0.0.1",
    "dialect": "mysql",
    "migrationStorageTableName": "sequelize_meta"
},
}
Ali Sherafat
  • 3,506
  • 2
  • 38
  • 51