0
0
Node.jsframework~10 mins

dotenv for environment configuration in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load environment variables from a .env file.

Node.js
require('[1]').config();
console.log(process.env.MY_VAR);
Drag options to blanks, or click blank then click option'
Adotenv
Bexpress
Chttp
Dfs
Attempts:
3 left
💡 Hint
Common Mistakes
Using other packages like express or fs instead of dotenv.
2fill in blank
medium

Complete the code to access the environment variable named PORT.

Node.js
const port = process.env.[1] || 3000;
console.log(`Server runs on port ${port}`);
Drag options to blanks, or click blank then click option'
APORT
Bport
CPath
DHOST
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'port' instead of uppercase 'PORT'.
3fill in blank
hard

Fix the error in the code to correctly load environment variables.

Node.js
import dotenv from '[1]';
dotenv.[2]();
console.log(process.env.SECRET_KEY);
Drag options to blanks, or click blank then click option'
Aconfig
Bdotenv
Cexpress
Dload
Attempts:
3 left
💡 Hint
Common Mistakes
Importing from wrong package names like 'express' or 'load'.
4fill in blank
hard

Fill both blanks to create a .env file and load a variable named API_KEY.

Node.js
API_KEY=[1]

require('dotenv').[2]();
console.log(process.env.API_KEY);
Drag options to blanks, or click blank then click option'
A"12345abcde"
Bconfig
Cload
D"apikey"
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the value or using wrong method name to load variables.
5fill in blank
hard

Fill all three blanks to create a Node.js script that loads dotenv, reads PORT, and starts a server.

Node.js
import dotenv from '[1]';
dotenv.[2]();
const port = process.env.[3] || 8080;
Drag options to blanks, or click blank then click option'
Adotenv
Bconfig
CPORT
Dexpress
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong package names or method names, or wrong variable case.