Skip to main content

How to Build and Test a Node.js Application

Configure a build configuration in BuildNinja to automatically install dependencies, run tests, and build a Node.js application. This configuration uses:

  • Native Git support to fetch source code.
  • Command Line runner to execute npm commands.
  • Artifacts and caching-ready structure to optimize future builds.

Prerequisites

Before you begin, ensure that:

  • You have access to a BuildNinja project.
  • Your Node.js repository contains a valid package.json.
  • Test and build scripts are defined, for example:
    "scripts": {
    "test": "npm test",
    "build": "npm run build"
    }

Step 1: Create Build Configuration

  1. Navigate to Projects.

    how-to-build-ninja-project-overview

  2. Select the project where you want to configure the build.

    how-to-how-to-project

  3. Click New Build Configuration.

    how-to-new-build-configuration-button

  4. Enter the following details:

    • Build Configuration Name (for example, Node.js Build & Test).
    • Description (optional).

    how-to-build-configuration-basic-information

  5. Click Create.

    how-to-build-configuration-basic-information-create-button

    For more details about creating and managing build configurations, see Configure and Edit BuildsBuilds in a CI/CD environment represent a defined set of execution steps that run automatically to build, test, package, or prepare an application for deployment..

Step 2: Configure VCS Settings

  1. Navigate to VCS Settings.

    how-to-node-vcs-settings

  2. Click Add VCS.

    how-to-node-vcs-add-vcs-button

  3. Enter the following details:

    • VCS Root Type: Git.
    • VCS Name: A unique identifier.
    • Repository URL: Git repository URL.
    • Branch: main, develop, or your target branch.
    • Checkout Directory: Optional, default is recommended.
    • Authentication Mode: Select the required authentication method.

    how-to-node-add-vcs-page

  4. Click Test Connection to verify access (optional).

    how-to-node-add-vcs-test-connection-button

  5. Click OK to add the VCS.

    how-to-node-add-vcs-ok-button

  6. Click Save to save the VCS Settings.

    how-to-node-vcs-settings-save-button

    note

    BuildNinja will now automatically fetch your source code from Git when the build runs.

Step 3: Configure Execution Steps

Step 3.1: Install Dependencies

  1. Navigate to Execution Steps.

    how-to-node-execution-steps

  2. Click Add Execution Step.

    how-to-node-add-execution-step-button

  3. Enter the following details:

    • Select Runner: Command Line
    • Step Name: Install Dependencies
    • Working Directory: Leave blank for default.
    • Commands:
      npm install

    how-to-node-add-execution-step-page

  4. Click OK to add the execution step.

    how-to-node-add-execution-step-ok-button

  5. Click Save to save the Execution Steps.

    how-to-node-execution-steps-save-button

Step 3.2: Run Tests

  1. Click Add Execution Step.

    how-to-node-add-execution-step-button-1

  2. Enter the following details:

    • Select Runner: Command Line
    • Step Name: Run Tests
    • Commands:
      npm test

    how-to-node-add-execution-step-page

  3. Click OK to add the execution step.

    how-to-node-add-execution-step-ok-button-1

  4. Click Save to save the Execution Steps.

    how-to-node-execution-steps-test-save-button

Step 3.3: Build Application

  1. Click Add Execution Step.

    how-to-node-build-add-execution-step-button

  2. Enter the following details:

    • Select Runner: Command Line
    • Step Name: Build Application
    • Commands:
      npm run build

    how-to-node-add-execution-step-page

  3. Click OK to add the execution step.

    how-to-node-build-add-execution-step-ok-button

  4. Click Save to save the Execution Steps.

    how-to-node-build-execution-steps-save-button

Artifacts allow you to store build outputs such as compiled files or bundles.

  1. Navigate to Artifacts.

    how-to-node-add-artifacts-page

  2. Click Add Artifact.

    how-to-node-add-artifact-button

  3. Enter the following details:

    • Name: Node Build Output
    • Condition: Only if build status is successful
    • Paths: dist/** or your project’s build output directory

    how-to-node-add-artifact-page

  4. Click OK to add the artifact.

    how-to-node-add-artifact-ok-button

  5. Click Save to save the Artifacts.

    how-to-node-add-artifacts-save-button

Step 5: Run Builds

Your build configuration is now complete.

Running a build executes the steps defined in the build configuration, such as installing dependencies, running tests, and generating build outputs. In BuildNinja, build configurations define what a build does and control when it runs.

Step 5.1: Run Build Manually

  • Click Run Build to start the build manually. Once triggered, the build enters the execution queue and starts automatically when a compatible agent becomes available.

    how-to-node-run-build-button

Step 5.2: Monitor Build Execution

While the build is running, you can view detailed logs for each execution step, including:

  • Dependency installation
  • Test execution
  • Build output

These logs help you verify successful execution and troubleshoot failures. For more details about viewing build logs, step status, and overall build results, see View Build ResultsBuild results provide detailed insights into each successful or failed build. You can review execution outcomes, identify issues, and access any generated artifacts..

how-to-node-execution-logs

Step 5.3: Schedule Build (Optional)

BuildNinja supports scheduled build triggers that allow builds to run automatically on a defined schedule. To learn how to configure and manage build triggers, see Schedule Build TriggersBuild triggers allow you to start the builds automatically based on a schedule. This helps streamline workflows and reduce the need for manual intervention..