Courseiva
Deployment →mediumMultiple Choice

DVA-C02 Deployment Practice Question

A team uses AWS CodeBuild to run automated tests. The buildspec.yaml file contains a 'pre_build' phase that sets environment variables. During a build, the build fails with 'Error: Cannot find module 'express' when running a Node.js application. The application's package.json is in the source root. What is the most likely cause?

⚠ Common exam trap

DVA-C02 often tests the misconception that CodeBuild automatically installs dependencies — candidates assume the runtime handles it, but you must explicitly run npm install in the buildspec.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

The buildspec does not include a command to run 'npm install' in the install or pre_build phase.

AWS CodeBuild runs each phase in the buildspec in order: install, pre_build, build, post_build. If the buildspec does not include an 'npm install' (or 'npm ci') command in the install or pre_build phase, the Node.js dependencies listed in package.json — including express — are never downloaded into node_modules. The build then fails when it tries to require('express'). The fix is to add 'npm install' to the install phase.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    The Node.js runtime version is incompatible with the express module.

    Why it's wrong here

    If the Node.js runtime version were incompatible with the `express` module, the error would typically manifest as a syntax error, a runtime exception during module loading, or unexpected behavior, not a "cannot find module" error. A "cannot find module" error specifically indicates that the module file itself was not located in the expected `node_modules` paths, implying it was never installed or its path is incorrect, rather than a version mismatch preventing its execution.

  • ✗

    The environment variable NODE_ENV is set to production, which skips devDependencies.

    Why it's wrong here

    The `express` module is a fundamental runtime dependency for most Node.js web applications, not a `devDependency`. `devDependencies` are typically installed only during development or testing phases, and `npm install` (without specific flags like `--production`) installs both. Even if `NODE_ENV` were set to `production`, `npm install` by default would still install `dependencies`, making this an unlikely cause for `express` not being found.

  • ✓

    The buildspec does not include a command to run 'npm install' in the install or pre_build phase.

    Why this is correct

    For Node.js projects, the `express` module, like other project dependencies, must be explicitly installed into the build environment. This is typically achieved by running `npm install` (or `yarn install`) within the `install` or `pre_build` phase of the CodeBuild `buildspec.yml`. Without this command, the `node_modules` directory will not be populated, leading to a "cannot find module 'express'" error when the application attempts to import it.

  • ✗

    The package.json file is not in the source root directory.

    Why it's wrong here

    The question stem explicitly states that the `package.json` file is located in the source root directory. The `npm install` command, when executed, expects to find `package.json` in the current working directory to determine which dependencies to install. If it were missing or in an incorrect location, `npm install` itself would likely fail or report an error about not finding a `package.json` file, rather than silently omitting `express`.

About these practice questions

This DVA-C02 question is part of Courseiva's 1,135-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Amazon Web Services exam blueprint

This DVA-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DVA-C02 exam.