After breaking my head looking for documentation - these are the steps I used to handle environment configuration:
Step 1: Install dotenv package
npm install --s dotenv
Add a .env
file to the root of your project (server/.env). Sample format in this file given below:
SampleKey=testValue
Require this file from the index.js file (I placed this on line 2)
// Addition of dotenv for access to process.env (environment variables)
const dotenv = require('dotenv').config();
You should be able to access keys from your file now as follows:
console.log(process.env.SampleKey);
dotenv
configuration inindex.js
(next to thepackage.json
) and it worked !!! If you want similar solution try... – Torrie