To get a value from .env
file in Javascript, you need to use a package called dotenv
.
Firstly, install the package by running this command in your project directory:
19 chars2 lines
Then, create a .env
file in the root directory of your project and add your environment variables like this:
index.tsx76 chars4 lines
In your Javascript code, require the dotenv
package and call its config()
method, which reads the .env
file and adds its contents to process.env
. You can then access the values of the environment variables using process.env.VARIABLE_NAME
.
index.tsx268 chars10 lines
gistlibby LogSnag