1

I am currently working on a reactjs project which has been created with create-react-app. env-cmd package is a little too old and is not under maintenance anymore so I'd like to use dotenv instead. Is there a way that I can specify a .env file just like we usually do with env-cmd but with the help of dotenv instead? Or is there a suggested method I should be following using dotenv?

Thanks in advance.

  • Does this answer your question? [dotenv file is not loading environment variables](https://stackoverflow.com/questions/42335016/dotenv-file-is-not-loading-environment-variables) – ThePyGuy Aug 11 '22 at 03:17

1 Answers1

0

You can specify the path with .config({path: "directory"})

    // Using require syntax    
    require("dotenv").config({ path: "../.env" });
    
    // Using import syntax
    import dotenv from "dotenv"
    dotenv.config({path: "../.env"})
Jim LK Yu
  • 148
  • 10
Liam Welsh
  • 194
  • 8