0
0
Microservicessystem_design~10 mins

Environment configuration in Microservices - 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 in a microservice.

Microservices
const config = process.env.[1];
Drag options to blanks, or click blank then click option'
ANODE_ENV
BCONFIG_PATH
CPORT
DSERVICE_NAME
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable that defines port or service name instead of environment.
2fill in blank
medium

Complete the code to read a configuration file path from environment variables.

Microservices
const configPath = process.env.[1] || './config/default.json';
Drag options to blanks, or click blank then click option'
ACONFIG_FILE
BCONFIG_PATH
CCONFIG_DIR
DCONFIG_LOCATION
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names that do not clearly indicate a file path.
3fill in blank
hard

Fix the error in the code to correctly parse environment variables for service port.

Microservices
const port = parseInt(process.env.[1], 10) || 3000;
Drag options to blanks, or click blank then click option'
APORT
BAPP_PORT
CSERVICE_PORT
DPORT_NUMBER
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-standard or custom variable names that may not be recognized by hosting platforms.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that filters environment variables starting with 'APP_'.

Microservices
const appEnvVars = Object.fromEntries(Object.entries(process.env).filter(([key, value]) => key.[1]('APP_') === [2]));
Drag options to blanks, or click blank then click option'
AstartsWith
BindexOf
C0
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using indexOf without comparing to 0, or using -1 incorrectly.
5fill in blank
hard

Fill all three blanks to create a function that loads environment variables with defaults.

Microservices
function getEnvVar(name, defaultValue) {
  return process.env[[1]] ?? [2] ?? [3];
}
Drag options to blanks, or click blank then click option'
Aname
BdefaultValue
C''
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using null as the last fallback instead of an empty string, which may cause issues when expecting strings.