express-babel icon indicating copy to clipboard operation
express-babel copied to clipboard

Need help to use dotenv after npm run build

Open ashokdey opened this issue 7 years ago • 1 comments

I am not able to understand that why dotenv is not working after building

In src/index.js, I am having the following code,

import path from 'path';
const envPath = path.resolve(__dirname, '../.env');

require('dotenv').config({ path: envPath});
import app from './app';

Now after running npm start, the .env file which is located in the root folder is not working, all the env variables are undefined. Am I missing something?

**Alternative ways ** These are the alternative ways I am using right now:

  • docker-compose
  • PM2 ecosystem.config.js

ashokdey avatar Oct 09 '18 06:10 ashokdey

You can just do:

import { load } from 'dotenv'

// Load .env file
load()

ndabAP avatar May 15 '19 09:05 ndabAP