0
0
Node.jsframework~10 mins

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();
Drag options to blanks, or click blank then click option'
Afs
Bexpress
Chttp
Ddotenv
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'express' instead of 'dotenv'.
Trying to read .env file manually without a package.
2fill in blank
medium

Complete the code to access the PORT environment variable with a default fallback.

Node.js
const port = process.env.[1] || 3000;
Drag options to blanks, or click blank then click option'
APATH
BHOST
CPORT
DNODE_ENV
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'HOST' instead of 'PORT'.
Forgetting to provide a default value.
3fill in blank
hard

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

Node.js
import dotenv from '[1]';

await dotenv.config();
Drag options to blanks, or click blank then click option'
Afs
Bdotenv
Chttp
Dpath
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'fs' or 'path' instead of 'dotenv'.
Trying to use 'await' with a synchronous method.
4fill in blank
hard

Fill both blanks to set a custom path for the .env file and load it.

Node.js
dotenv.config({ path: [1] + '[2]' });
Drag options to blanks, or click blank then click option'
A__dirname + '/configs/'
B'.env'
C'.env.local'
D'/env/'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect folder or filename strings.
Not concatenating strings properly.
5fill in blank
hard

Fill all three blanks to create a config object that reads NODE_ENV, sets a default, and exports it.

Node.js
const config = {
  env: process.env.[1] || '[2]',
  port: process.env.PORT || [3]
};

export default config;
Drag options to blanks, or click blank then click option'
ANODE_ENV
Bdevelopment
C3000
DHOST
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong environment variable names.
Not providing default values.