简体   繁体   中英

Environment variables in NodeJS depenency

Environment variables in NodeJS depenency

I have a NodeJS application which has a dependency of mine

my-base-module: git+https://myuser:mytoken@gitlab.com/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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM