Build and Test a Node.js App in Azure DevOps

45 minutes
  • 4 Learning Objectives

About this Hands-on Lab

In this hands-on lab, you will be taking an existing Node.js app and running it through a DevOps pipeline in Azure Pipelines. Also within Azure Pipelines, you will modify the deployment YAML in order to specify the version of Node.js and publish the build results to Azure Test Plans.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a New Azure DevOps Organization
  1. Log in to the Azure portal, click on All Services, and select Azure DevOps.
  2. Click on the My Azure DevOps Organizations link (this will open a new tab).
  3. Once the fields have auto-populated with the name, email, and location, click on the Continue button.
  4. Under Get Started with Azure DevOps click the Create new organization button.
  5. If prompted to agree to the terms of service, click the Continue button.
  6. Choose a name for your new DevOps organization (the default will suffice).
  7. Choose the location Central US for the region to host your projects in and click Create.
  8. In the Project Name field, enter "nodejs" and click the Create Project button.
Create a Repository for the Application in an Azure Repo
  1. From within your Azure DevOps organization, click on Repos in the menu on the left-hand side of the screen.
  2. On the page titled "nodejs is empty. Add some code!", click the grey Import button.
  3. On the popup labeled Import a Git Repository, select Git as a source type and paste in the following URL:
  4. Click on Import.
Create a New Pipeline and Run the First Build
  1. From within your Azure DevOps organization, click on Pipelines from the menu on the left-hand side of the screen.
  2. Click on the New pipeline button.
  3. On the Connect step, under Where is your code, select Azure Repos Git.
  4. On the Select step, under Select a repository, select nodejs.
  5. On the Configure step, under Configure your pipeline, select Node.js.
  6. On the Review step, to the right of Review your pipeline YAML, click the Save and run button.
  7. On the popup, under Save and Run, enter a commit message (the default message will suffice), select Commit directly to the master branch and click the Save and run button again.
  8. Verify that the first build was successful by watching the output.
Edit the Build to Include a Specific Version of Node.js and Publish the Test Results
  1. From within your Azure DevOps organization, click on Repos from the menu on the left-hand side of the screen.
  2. Select the file named azure-pipelines.yml and click on Edit.
  3. Under the task NodeTool@0 change the versionSpec from 10.x to 10.14.
  4. Click on Commit, enter a commit message (the default will suffice) and click the Commit button.
  5. In the code repository, verify there’s a file named test.js in the ./tests directory.
  6. Select the package.json file from within the code repository.
  7. Verify that mocha-junit-reporter is installed as a dependency.
  8. Click on Pipelines from the left-hand menu bar.
  9. Click nodejs.
  10. In the upper-right corner of the screen, select the grey Edit button.
  11. Place the cursor at the bottom of the azure-pipelines.yml file, under the script step.
  12. On the right-hand side of the screen under Tasks, use the search bar to search for the task "Publish Test Results".
  13. Select Publish Test Results and under Test Result Format, choose JUnit and under Test results files, type "**/TEST-RESULTS.xml".
  14. Leave everything else as default and click the Add button at the bottom of the screen.
  15. In the upper-right corner of the screen, click the Save button.
  16. Enter a commit message (the default will suffice), and choose Commit directly to the master branch. Then click the Save button.
  17. In the breadcrumb link navigation at the top, click Builds.
  18. Select the most recent build (at the top) from the history.
  19. Verify that the build was successful by watching the output on the screen.
  20. Click on Test Plans from the left menu bar.
  21. Under Test Plans, click on Runs.
  22. Double-click on the most recent test run and view the outcome.

Additional Resources

In order to integrate the code for an application and follow DevOps best practices, you will be creating a DevOps pipeline within Azure. The main application (located here: is running version 10.14 of node.js, so you will need to specify that in your pipeline. Also, within the pipeline, you need to test the application using npm to ensure that the packages run according to the provided test script specified in the package.json file. To complete this hands-on lab, you must publish the test results to Azure Test Plans at the end of the build.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?