I am trying to use the dotenv NPM package and it is not working for me. I have a file config/config.js with the following content:
Working Solution:
If you are using webpack (which you definitely should), use a very handy plugin dotenv-webpack which solves the issue of reading environment variables from .env file
Make sure
.envis in root directory of your project.
Steps to install the plugin:
npm i -D dotenv-webpack webpack.config file: const Dotenv = require('dotenv-webpack');
module.exports = {
...
plugins: [
new Dotenv(),
...
],
...
};
Now you can call any environment variable defined in .env file using process.env in any js file