0
0
Node.jsframework~5 mins

dotenv for environment configuration in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Apackage.json
B.env
Cconfig.json
Dsettings.js
Which method do you call to load variables from .env using dotenv?
Adotenv.config()
Bdotenv.init()
Cdotenv.start()
Ddotenv.load()
Where are environment variables stored after loading with dotenv?
Aglobal.env
Bwindow.env
Cprocess.env
Dmodule.exports
Why should you add .env to your .gitignore file?
ATo share environment variables with the team
BTo prevent large files from being committed
CTo speed up git operations
DTo avoid committing sensitive information
If process.env.API_KEY is undefined, what does it mean?
AAPI_KEY is not defined in the environment
BAPI_KEY is set to an empty string
Cdotenv failed to load
DAPI_KEY is a number
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.