Recall & Review
beginner
What is the purpose of the dotenv package in Node.js?
dotenv loads environment variables from a .env file into process.env, allowing you to keep configuration separate from code.
Click to reveal answer
beginner
How do you load environment variables using dotenv in a Node.js project?
You require dotenv and call dotenv.config() at the start of your application to load variables from the .env file into process.env.
Click to reveal answer
beginner
What should you NOT do with your .env file in a project?
You should NOT commit your .env file to version control because it may contain sensitive data like API keys or passwords.
Click to reveal answer
beginner
How can you access an environment variable named API_KEY in your Node.js code after using dotenv?
You access it with process.env.API_KEY, which returns the value as a string or undefined if not set.
Click to reveal answer
intermediate
Why is using dotenv helpful when working on a team or deploying an app?
dotenv helps keep environment-specific settings outside code, so each developer or server can have its own config without changing the codebase.
Click to reveal answer
What file does dotenv read to load environment variables?
✗ Incorrect
dotenv reads the .env file by default to load environment variables.
Which method do you call to load variables from .env using dotenv?
✗ Incorrect
The correct method to load environment variables is dotenv.config().
Where are environment variables stored after loading with dotenv?
✗ Incorrect
Environment variables are stored in process.env in Node.js.
Why should you add .env to your .gitignore file?
✗ Incorrect
The .env file often contains sensitive data, so it should not be committed to version control.
If process.env.API_KEY is undefined, what does it mean?
✗ Incorrect
If process.env.API_KEY is undefined, it means the variable was not set in the environment or .env file.
Explain how dotenv helps manage environment variables in a Node.js project.
Think about how you keep secrets or settings outside your code.
You got /4 concepts.
Describe best practices for using a .env file safely in a team project.
Consider security and collaboration.
You got /4 concepts.