0
votes

Environment variables in NodeJS depenency

I have a NodeJS application which has a dependency of mine

my-base-module: git+https://myuser:[email protected]/organization/my-base-module.git#v1.0.0

I am also using the dependency dotenv, which in development I use the file .env and in other environments I pass the variables through docker environment variables

The problem I have, and I do not know why and how to solve it is that in my-base-module I do not share the same environment variables (and I need it to). It is like the variables loose the reference

require('dotenv').config(); const env = process.env.NODE_ENV;

for example in that bit of code the NODE_ENV variable inside my-base-module is undefined. However in the container is defined and with the right value

Update 1

I am requiring dotenv in both my-application and my-base-module. If I enter to the container and I do $ echo $NODE_ENV. I get production.

If my application process.env.NODE_ENV also holds production. But in the dependency process.env.NODE_ENV is undefined

I will try to do some github repositories to reproduce it

1
are you requiring dotenv in my-base-module or in your application code? In your entry point, what are you getting for process.env.NODE_ENV value?. It will help if you post a bit of your application code and your package code. - Marcos Casagrande

1 Answers