0
0
Node.jsframework~10 mins

Why production setup differs from development in Node.js - Test Your Understanding

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

Complete the code to import the environment variables package in Node.js.

Node.js
const dotenv = require('[1]');
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' to load environment variables.
Forgetting to install the 'dotenv' package before requiring it.
2fill in blank
medium

Complete the code to set the Node.js environment mode to production.

Node.js
process.env.NODE_ENV = '[1]';
Drag options to blanks, or click blank then click option'
Aproduction
Bstaging
Ctest
Ddevelopment
Attempts:
3 left
💡 Hint
Common Mistakes
Setting NODE_ENV to 'development' when deploying to production.
Using an undefined environment mode string.
3fill in blank
hard

Fix the error in the code to correctly start the server only in production mode.

Node.js
if (process.env.NODE_ENV === '[1]') {
  app.listen(3000);
}
Drag options to blanks, or click blank then click option'
Aproduction
Bprod
Cdevelopment
Dlive
Attempts:
3 left
💡 Hint
Common Mistakes
Using shorthand like 'prod' instead of 'production'.
Not matching the case exactly.
4fill in blank
hard

Fill both blanks to create a conditional that logs debug info only in development mode.

Node.js
if (process.env.NODE_ENV === '[1]') {
  console.[2]('Debug info');
}
Drag options to blanks, or click blank then click option'
Adevelopment
Bproduction
Clog
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Logging debug info in production mode.
Using console.error instead of console.log for debug messages.
5fill in blank
hard

Fill all three blanks to create a configuration object that uses different database URLs based on environment.

Node.js
const config = {
  dbUrl: process.env.NODE_ENV === '[1]' ? process.env.[2] : process.env.[3]
};
Drag options to blanks, or click blank then click option'
Aproduction
BDEV_DB_URL
CPROD_DB_URL
Ddevelopment
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the environment names in the condition.
Using the wrong environment variable names for the URLs.