Complete the code to load environment variables from a .env file.
require('[1]').config();
The dotenv package loads environment variables from a .env file into process.env.
Complete the code to access the PORT environment variable with a fallback value.
const port = process.env.[1] || 3000;
process.env.PORT accesses the port number set in environment variables. The fallback 3000 is used if PORT is not set.
Fix the error in the code to correctly use environment variables in Express.
app.listen([1], () => {
console.log(`Server running on port ${port}`);
});process.env.PORT directly without fallback.The variable port holds the port number with fallback. Using port here ensures the server listens on the correct port.
Fill both blanks to set a default environment and log it.
const env = process.env.[1] || '[2]'; console.log(`Running in ${env} mode`);
NODE_ENV is the standard environment variable for the app mode. The default is usually set to development for local testing.
Fill all three blanks to create a config object using environment variables.
const config = {
host: process.env.[1] || 'localhost',
port: process.env.[2] || 5432,
user: process.env.[3] || 'admin'
};This config object uses environment variables for database connection details with sensible defaults.