Skip to content

NODE_ENV and stage collides to each other  #150

@rostislav-simonik

Description

@rostislav-simonik

Is your feature request related to a problem? Please describe.
NODE_ENV and stage are two different things,

NODE_ENV usually controls let's say for the sake of simplicity just "optimizations"

  • NODE_ENV=development -> very verbose, non optimised
  • NODE_ENV=production -> silent, optimised

stage represents where the application should be deployed, it can specify different database, file storage etc.

  • stage=development - for development purposes
  • stage=qa - for acceptance testing
  • stage=staging - preproduction testing
  • stage=production - production environment

so you can have mix like

  • stage=development, NODE_ENV=development
  • stage=qa, NODE_ENV=production
  • stage=staging, NODE_ENV=production
  • stage=production, NODE_ENV=production

because of getEnvironment() function, it's impossible to differentiate by stage if NODE_ENV has been specified as well. and it must be specified due to other toolings that required that env variable.

  getEnvironment(options) {
    return (
      process.env.NODE_ENV || options.env || options.stage || 'development'
    );
  }

Describe the solution you'd like
Not sure what would be the best, but I'd suggest completely remove NODE_ENV from that setup, but because we don't want to break existing usage, I'd introduce some option

custom:
  dotenv:
    # default: false
    ignoreNodeEnv: true

and to adjust getEnvironment() like this

  getEnvironment(options) {
    return (
       !this.config.ignoreNodeEnv && process.env.NODE_ENV || options.env || options.stage || 'development'
    );
  }

Describe alternatives you've considered
Writing own parser donEnvParser

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions