To use .env in JavaScript, you can use dotenv package which loads environment variables from a .env file into process.env. Here's how you can use it:
dotenv package using npm.19 chars2 lines
50 chars4 linesdotenv at the beginning of your JavaScript file.index.tsx27 chars2 lines
process.env.index.tsx140 chars8 linesThis will output:
index.tsx62 chars6 linesMake sure to add .env to .gitignore file to keep your sensitive data out of version control.
gistlibby LogSnag