Install dotenv

$ yarn add dotenv

in your entry file

const path = require('path');
const fs = require('fs');

// reading env file
let envFilePath = path.resolve(process.cwd(), '.env');
const environment = process.env.NODE_ENV || 'development';
if (environment === 'production') {
  envFilePath += '.production';
}

if (environment === 'staging') {
  envFilePath += '.staging';
}

if (!fs.existsSync(envFilePath)) {
  throw Error('You must specify env file based on your environment');
}

require('dotenv').config({ path: envFilePath });

in your .gitignore

.env*
!.env.example