const environments = {};
environments.staging = {
port: 5000,
envName: 'staging'
}
environments.production = {
port: 3000,
envName: 'production'
}
//Determine which env was pass
const currentEnvironment = typeof(process.env.NODE_ENV) === 'string' ? process.env.NODE_ENV : 'staging';
// export corresponding env object
const environmentsToExport = typeof(environments[currentEnvironment]) === 'object' ? environments[currentEnvironment] : environments.staging;
console.log(environments) Result- {port: 5000,envName: 'staging'}
console.log(currentEnvironment) Result- 'staging'
console.log(environments[currentEnvironment]) Result- Undefined
environments[currentEnvironment] – why the result is undefined???
The result should be the property of the object. The env variable is passed correctly.