Apr 10, 2018

Deploying a Node.js Web App on Azure

Aaron Wolin

Aaron Wolin

Deploying a Node.js Web App on Azure

Azure has grown as a cloud services provider in the recent years, rivaling AWS and increasing its 2017 revenue by 97% year-over-year. Azure’s expansion has brought rise to using the Platform as a Service (PaaS) offerings outside of traditional Microsoft-associated frameworks like .NET, in part because their documentation provides quick-start tutorials for using the PaaS Azure App Service with multiple languages and supports both Windows and Linux deployments.

To explore Azure’s cloud setup and deployment, we recently created a small website using Node.js and Azure App Service. Microsoft has a great tutorial for starting off with Node.js as a web app. This guide is intended as a supplement to the main installation and PaaS setup, providing our recommended enhancements for a successful Node.js and Azure project.

Set up Deployments Through Kudu

Kudu is the backbone of App Service deployments through Git, and it was instrumental in helping us set up an automatic deployment pipeline for our small application.

Azure App Service supports deployments from multiple sources including FTP servers, continuous deployments, and locally from Git. Both the continuous deployments and local Git deployments rely on Kudu, so learning this deployment engine will be essential for any project that relies on Git for version control.

Once you follow the tutorial of your choice to deploy your app, explore Kudu by going to your site at YOUR-APP-SERVICE-NAME> Here you can watch a log stream of your application, view your app and environment parameters, and even browse your app’s directory structure to alter configurations and code sans-deployments. These features were essential when first setting up and debugging the application.

Configure the Package Management to Use Yarn

During our deployments, we often encountered issues where some of the app’s Node packages would not install properly via npm. We were able to fix this by switching to Yarn for package management, which provided more reliable, faster deployments.

To switch to using Yarn during Kudu deployments:

1. Navigate to your project’s source code locally and run azure site deploymentscript –node.

  • This will download the default node.js Kudu cmd and .deployment files to your local root directory.

2. Open the cmd file.

3. Update the cmd file to alter the deployment steps, from Stefan Gordon’s tutorial:

:: 3. Install Yarn echo Verifying Yarn Install. call :ExecuteCmd !NPM_CMD! install yarn -g

:: 4. Install Yarn packages echo Installing Yarn Packages. IF EXIST "%DEPLOYMENT_TARGET%\package.json" ( pushd "%DEPLOYMENT_TARGET%" call :ExecuteCmd yarn install --production IF !ERRORLEVEL! NEQ 0 goto error popd )

4. Save and commit the new deployment files, and redeploy to Azure.

Utilize Azure AD

Our web application used Node.js, Express, and Passport to handle authentication, and we wanted to integrate the app to use our existing Azure Active Directory (Azure AD) for seamless employee authentication.

Azure AD provides a Passport module to support the authentication, and we hope these helpful tips will assist your setup.

  • Set up your app’s client ID and secret for secure access to Azure AD.

  • If you’re following the Azure AD tutorial above, you’ll need to use a Microsoft Identity v1 endpoint for the passport OIDC identityMetadata parameter. For v2 endpoints, review the documentation here and make sure to register your app using the new registration portal,

  • In some cases, you may want to accept access to your application on behalf of all users registered in your Azure AD. This will prevent an access prompt from appearing for each user and allow a seamless sign on experience for authorized users.To do this, you will need to create your initial authentication callback with “prompt: ‘admin_consent’”. An Azure AD user with global admin permissions can then authenticate to your app through AD and accepts on behalf of all users; after the admin authentication, you can remove this parameter and redeploy.

/* POST Azure AD callback */'/auth/openid/return', passport.authenticate('azure-openidconnect', { successRedirect: '/home, failureRedirect: '/login', failureFlash: true, prompt: 'admin_consent' }), function(req, res, next) {

Interested in bootstrapping your Azure PaaS environment or using Node.js? Reach out to us at

Conversation Icon

Contact Us

Ready to achieve your vision? We're here to help.

We'd love to start a conversation. Fill out the form and we'll connect you with the right person.

Searching for a new career?

View job openings