To configure a .env file in a Node.js project using Javascript, you can follow these steps:
index.tsx19 chars2 lines
Create a .env file in the root of your project directory.
Add your environment variables to the .env file in KEY=VALUE format:
index.tsx56 chars4 lines
dotenv package:index.tsx27 chars2 lines
process.env.KEY. For example:index.tsx115 chars4 lines
In the above code snippet, we're accessing the environment variables PORT, DB_URL, and SECRET_KEY using process.env. We've also set a default value for PORT in case it's not defined in the .env file.
Note: It's important to add the .env file to your .gitignore file, so that you don't accidentally commit sensitive information to version control.
gistlibby LogSnag