Complete the code to load environment variables from a .env file.
require('[1]').config(); console.log(process.env.MY_VAR);
The dotenv package loads environment variables from a .env file into process.env.
Complete the code to access the environment variable named PORT.
const port = process.env.[1] || 3000; console.log(`Server runs on port ${port}`);
Environment variables are case-sensitive. The variable is named PORT in uppercase.
Fix the error in the code to correctly load environment variables.
import dotenv from '[1]'; dotenv.[2](); console.log(process.env.SECRET_KEY);
The package name to import is dotenv. The method to load variables is config().
Fill both blanks to create a .env file and load a variable named API_KEY.
API_KEY=[1] require('dotenv').[2](); console.log(process.env.API_KEY);
The .env file stores variables as key=value pairs. The value should be quoted if it contains letters and numbers. The method to load is config().
Fill all three blanks to create a Node.js script that loads dotenv, reads PORT, and starts a server.
import dotenv from '[1]'; dotenv.[2](); const port = process.env.[3] || 8080;
Import dotenv, call config() to load variables, then read PORT from process.env.