'node / react after installing .env module, error for "fs"

I need to read some environmental variables on my node/react project.

After I installed dotenv

npm install dotenv --save

I import dotenv in my js file:

require('dotenv').config();

then I get an error for "fs"

Module not found: Error: Can't resolve 'fs' in '/Users/Na/projects/laa/node_modules/dotenv/lib'

So, is this because "file system" is not installed?

how to fix it?

cheers



Solution 1:[1]

For the latest releases, you don't need the dotenv module any more. Environment variables are available with [email protected] and higher. According to Create React App docs:

Environment Variables is available with [email protected] and higher.

So the only thing you need to do is to create the .env file and put your variables in it with the prefix REACT_APP_{your variable name}, and then you can use any variable in your code using:

process.env.REACT_APP_{your variable name}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abdullah Almofleh