Skip to content

env arg isn't setting NODE_ENV  #413

@JonathanTech

Description

@JonathanTech

https://github.com/sequelize/cli/blob/master/lib/helpers/generic-helper.js#L28

Also, this argument isn't documented (as far as I could tell after reading the readme).

Documentation might be enough, but I did find it odd that it internally switches the environment, but doesn't set NODE_ENV which dependent scripts like config.js might be expecting to happen.

My example config.js file that this doesn't work with:

config/config.js

"use strict";
const config = require('./index').dbConfig 
let configEnv = {}
configEnv[process.env.NODE_ENV || "development"] = config;

module.exports = configEnv

config/index.js

"use strict";
process.env.NODE_ENV = process.env.NODE_ENV || "development"
console.log(`Company Config : Using Environment "${process.env.NODE_ENV}"`)
require('dotenv').config() //load .env first if it exists
require('dotenv').config({path: './config/.env.' + process.env.NODE_ENV}) //then load env file if env values are missing or a .env file doesn't exist
module.exports = {
  authenticationServer: process.env.AUTHENTICATION_SERVER,
  zipkinServiceName   : process.env.ZIPKIN_SERVICE_NAME,
  zipkinLoggerEndpoint   : process.env.ZIPKIN_LOGGER_ENDPOINT,
  dbConfig:{
    username: process.env.DB_USER_NAME,
    password:process.env.DB_PASSWORD || null,
    database:process.env.DB,
    host: process.env.DB_HOST,
    dialect: process.env.DB_DIALECT,
    logging: process.env.DB_QUERY_LOGGING ? undefined : false
  }
}

using sequelize version --env=test
outputs

Company Config : Using Environment "development"

Sequelize [Node: 6.1.0, CLI: 2.5.1, ORM: 3.24.3]

Company Config : Using Environment "development"
Loaded configuration file "config/config.js".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions