Node.js Professional Standards & Competencies 2 — Questions and Answers
Question 1: Which Node.js best practice helps prevent callback hell in production codebases?
- Using nested callbacks for all async operations
- Adopting Promises or async/await to flatten async flows (Correct answer)
- Calling all I/O operations synchronously
- Increasing the event loop tick rate
Correct answer: Adopting Promises or async/await to flatten async flows
Promises and async/await flatten deeply nested callbacks, improving readability and maintainability.
Question 2: What is the professional standard for handling uncaught exceptions in a Node.js production service?
- Silently swallow all exceptions to keep the process alive
- Log the error and allow the process to crash, relying on a process manager to restart it (Correct answer)
- Catch every exception in a global try/catch and continue execution
- Disable exception propagation via --no-warnings flag
Correct answer: Log the error and allow the process to crash, relying on a process manager to restart it
The recommended pattern is to log the error, perform cleanup if needed, and let the process exit so a process manager (PM2, systemd) can restart it cleanly.
Question 3: Which tool is the professional standard for enforcing consistent code style across a Node.js team?
- A shared .vimrc file
- ESLint with a shared config and Prettier for formatting (Correct answer)
- Manual code reviews without automated checks
- Commenting code style guidelines in each file
Correct answer: ESLint with a shared config and Prettier for formatting
ESLint catches code quality issues and Prettier enforces formatting, together standardizing style across teams.
Question 4: What does semantic versioning (semver) require when you make a backward-incompatible API change in a Node.js package?
- Increment the patch version (e.g., 1.0.1)
- Increment the minor version (e.g., 1.1.0)
- Increment the major version (e.g., 2.0.0) (Correct answer)
- Add a pre-release tag without changing the version
Correct answer: Increment the major version (e.g., 2.0.0)
Breaking changes require a major version bump so consumers know to expect incompatibilities.
Question 5: A developer stores API keys directly in source code committed to a public GitHub repository. What professional standard was violated?
- The principle of least privilege
- The practice of keeping secrets out of source control (Correct answer)
- The convention of using camelCase variable names
- The rule against using third-party npm packages
Correct answer: The practice of keeping secrets out of source control
Secrets must be stored in environment variables or secret managers, never committed to version control.
Question 6: What is the recommended approach for managing environment-specific configuration in Node.js applications?
- Hardcode values for each environment inside the application logic
- Use environment variables loaded via process.env, often with a .env file for local development (Correct answer)
- Store all config in a JSON file committed to the repository
- Use global variables set at the OS level only in production
Correct answer: Use environment variables loaded via process.env, often with a .env file for local development
Environment variables decouple config from code, following the 12-factor app methodology.
Question 7: Which strategy best demonstrates professional dependency management in a Node.js project?
- Installing all packages globally to share across projects
- Regularly auditing dependencies with npm audit and pinning versions in package-lock.json (Correct answer)
- Deleting package-lock.json to always get the latest versions on install
- Copying node_modules into the git repository
Correct answer: Regularly auditing dependencies with npm audit and pinning versions in package-lock.json
npm audit identifies vulnerabilities and package-lock.json ensures reproducible installs across environments.
Which Node.js best practice helps prevent callback hell in production codebases?