Skip to main content

Deploying a Node.js project to Azure App Services using Azure DevOps pipelines

Deploying a Node.js project to Azure App Services using Azure DevOps pipelines is a robust way to automate deployment processes and integrate continuous integration and deployment (CI/CD) practices into your workflow. This guide will walk you through the setup of an Azure DevOps pipeline to deploy a Node.js application from GitHub or Azure Repos to Azure App Services.

Prerequisites

Before you begin, ensure you have the following:

  • An Azure account. You can sign up for a free account here.
  • A GitHub or Azure Repos account with your Node.js project.
  • An Azure DevOps account. Create one here if you don't have it.

Step 1: Prepare Your Node.js Application

Make sure your Node.js application is ready and includes a package.json file in the root. This file is crucial as it contains dependency information and scripts needed for your application.

Step 2: Create an Azure Web App

  1. Log into Azure Portal: Visit https://portal.azure.com.
  2. Create a Web App:
    • Click on "Create a resource".
    • Search for and select "Web App".
    • Click "Create".
    • Enter the details for:
      • Subscription and Resource Group
      • Web App Name
      • Publish: Code
      • Runtime stack: Select the appropriate Node.js version
      • Region
    • Click "Review and Create" and then "Create".

Step 3: Set Up Azure DevOps Project

  1. Create a New Project in Azure DevOps:
    • Log into your Azure DevOps account at https://dev.azure.com/.
    • Click "New project", enter a name, description, and visibility. Then, click "Create".





Step 4: Configure CI/CD Pipeline

  1. Connect Repository:

    • In your Azure DevOps project, go to "Pipelines" > "Pipelines" and click "Create Pipeline".
    • Connect to GitHub or Azure Repos and select your repository.
  2. Configure Pipeline:

    • Azure DevOps may suggest a pipeline configuration based on your project. For Node.js, you might start with a simple YAML pipeline. Modify it according to your needs.
  3. Sample YAML Configuration:

    yaml
    trigger: branches: include: - main pool: vmImage: 'ubuntu-latest' steps: - task: NodeTool@0 inputs: versionSpec: '14.x' displayName: 'Install Node.js' - script: | npm install npm build displayName: 'npm install and build' - task: AzureWebApp@1 inputs: azureSubscription: '<Azure_Service_Connection>' appType: 'webAppLinux' appName: '<Your_App_Name>' runtimeStack: 'NODE|14-lts' startUpCommand: 'npm start' package: '$(Build.ArtifactStagingDirectory)'
    • Replace <Azure_Service_Connection> with your Azure service connection name.
    • Replace <Your_App_Name> with the name of the Azure Web App.
  4. Save and Run Pipeline:

    • Save the YAML file and run the pipeline.
    • Azure DevOps will execute the CI/CD pipeline, which builds your application and deploys it to Azure App Services.

Step 5: Verify Deployment

After the pipeline execution finishes:

  • Go to the Azure portal.
  • Open your App Service and click on the URL to see your deployed application.

Step 6: Monitor and Maintain

Set up monitoring with Azure Monitor and regularly update your pipeline configuration to meet new requirements or dependencies.

Conclusion

Setting up a CI/CD pipeline with Azure DevOps for a Node.js application automates your deployment process, enhances productivity, and ensures your application is always deployed with the latest updates in a stable manner. This setup not only supports a more streamlined workflow but also integrates well with other Azure services for monitoring, scaling, and managing your application in production.

Comments

Popular posts from this blog

DevOps Vs DevSecOps

   DevOps and DevSecOps are two methodologies that have gained traction in the IT industry for streamlining software development and deployment. However, their approach to security and operations differs, making each suitable for different types of projects and organizational needs. Let's explore DevOps versus DevSecOps with a real-time example, focusing on their distinctions, integration, and practical applications. DevOps: The Foundation DevOps is a cultural and professional movement that emphasizes collaboration and communication between software developers and other IT professionals while automating the process of software delivery and infrastructure changes. It aims to shorten the development life cycle and provide continuous delivery with high software quality. Core Principles: Continuous Integration and Continuous Deployment (CI/CD): Automate building, testing, and deployment of applications. Collaboration: Breaking down silos between teams (developers, IT operations...

Git Cheat Sheet

  Git Cheat Sheet Category Command Description Setup git config --global user.name "[name]" Set a name that will be attached to your commits and tags. git config --global user.email "[email]" Set an email that will be attached to your commits and tags. git init Initialize a new git repository in the current directory. git clone [url] Clone a repository into a new directory. Stage & Snapshot git status Show modified files in the working directory, staged for your next commit. git add [file] Add a file as it looks now to your next commit (stage). git reset [file] Unstage a file while retaining the changes in the working directory. git diff Show diff of what is changed but not staged. git diff --staged Diff of what is staged but not yet committed. git commit -m "[message]" Commit your staged content as a new commit snapshot. Branch & Merge git branch List all of the branches in your repo. git branch [name] Create a new branch at the current commit. gi...