In Node.js projects, environment variables often differ between development and production. Why is this important?
Think about what kind of data you want to expose in development versus production.
Production uses real, secure data like API keys and database URLs. Development uses safe, local or test data to avoid risks.
Consider a Node.js app that logs detailed debug info in development but also in production. What is the likely effect?
Think about performance and security when logging too much in production.
Verbose logging in production can slow the app and leak sensitive data, so it is usually turned off.
In Node.js, you want to load variables from a .env file only when not in production. Which code does this correctly?
if (process.env.NODE_ENV !== 'production') { require('dotenv').config(); }
Check the condition carefully for loading dotenv only outside production.
We load dotenv only if NODE_ENV is not 'production'. Option A uses !== correctly. Option A uses assignment (=) which is wrong.
Given this code snippet, what will be logged if NODE_ENV is set to 'production'?
if (process.env.NODE_ENV === 'production') { console.log('Running in production mode'); } else { console.log('Running in development mode'); }
Check the condition comparing NODE_ENV to 'production'.
If NODE_ENV equals 'production', the first console.log runs, printing 'Running in production mode'.
Consider this Node.js code snippet used in production. It fails to start with an error. What is the cause?
if (process.env.NODE_ENV !== 'production') { require('dotenv').config(); } console.log(process.env.API_KEY.length);
Think about what happens if API_KEY is missing in production.
In production, dotenv is not loaded, so API_KEY is undefined. Accessing length on undefined throws an error.