dotenv multiple environment does not working on azure

45 Views Asked by At

I have .env.dev and .env.prod files in my root folder. Im trying to get informations with dotenv. I have code block for importing env "require('dotenv').config()". Its working on local side when I create build and start inside of dist folder everything working as expecting. But when I push the code to azure its not working.

// env.dev & Prod


  PORT=
  MONGO_URI=
  JWT_SECRET=
  MAIL_HOST= 
  MAIL_USER= 
  MAIL_PASS= 

//  main.js
require('dotenv').config()

const URI = process.env.MONGO_URI || ""

console.log("URI", URI)

const PORT = process.env.PORT || 8000

// package.json
"start": "node dist/index.js",
"dev": "tsc && dotenvx run --env-file=.env.dev --  nodemon index.ts",
"build": "dotenvx run --env-file=.env.prod --  npx tsc --build"

my project written with TypeScript.

Env File exampel

when I try to log URI it comes empty string because process.env does not includes MONGO_URI on production

code block for getting mongo uri from env

I need to solve that error. I looked for documentation of dotenv-vault,dotenvx and dotenv didnot worked;

0

There are 0 best solutions below