Jon Rumsey

An online markdown blog and knowledge repository.


Project maintained by nojronatron Hosted on GitHub Pages — Theme by mattgraham

Deploy NodeJS To Azure App Service

Table of Contents

Objectives

Azure Services

Subscriptions contain Resource Groups that contain Resources including instances of services e.g. Azure App Service.

Resource Group:

Tools

To Create A Resource Group, use:

Use the Azure tools to:

Note: From my workstation, the Azure Extension was very slow.

App Service Plan

Express.js is a server-side app, so the following service plans would be appropriate:

App Service Plan defines the compute resources for the webapp to run on (an abstracted 'server farm').

One or more apps can be hosted within the same App Service Plan.

Resource-intensive apps should be moved into their own App Service Plan to avoid negative impacts on other apps in the same plan.

App Settings at Creation

Required Configuration Items:

Note: It looks like Application Insights must be enabled at the Azure Portal.

Post-Creation Settings

Env Settings

const port = process.env.PORT || 8080; WEBSITES_PORT 3000 SCM_DO_BUILD_DURING_DEPLOYMENT True

Public WebApp URL

URL like: https://your-resource-name.azurewebsites.net/

Default Web App

Change 'hostingstart.html' static file to branding or contact information, as a splash page until the site is fully deployed.

Authentication

Wide-open at initial deployment.

Post-deployment, configure to use social sign-ins, an AD authentication service, or a custom authentication platform.

Some programmatic changes within the App might be necessary to enable authentication and authorization.

App Service Node Components

Application Settings: Env Vars

Databases: Only populated if DB is created at same time as this App Service.

Deployments: List

Files: This is where hostingstart.html is stored. Other files will be stored here for this resource to use.

Logs: Running App Log Files.

WebJobs: Not available for Linux Apps.

Deployment Slots: Slots to expanding deployments to handle higher loads.

NPM Packages

Recommendation is to allow Azure to install all NPM Packages:

SCM_DO_BUILD_DURING_DEPLOYMENT=true

Optional: Store custom NPM Packages in Azure Storage and install the modules from there.

Build Process

Build process should run 'npm install'.

Optional: Consider using the npm script 'postinstall' to run more build tasks for the app.

Deployment Tasks

Post-deployment tasks to consider:

Automate Deployments

Verify Files

This can be done in Azure Portal or via VS Code.

Partial Deployment

Use Azure SSH or bash in-browser portals or VS Code 'files' to remove or add files to an existing deployemnt.

Slots

If in a paid Subscription and Tier, Slots can be used to Blue-Green deploy in real time including reversing deployments and showingn temporary messages to site visitors.

Code Deployment Sources

VS Code can deploy a local folder to an App Service. This uses a ZIP file to package files for transport.

Zip Deploy actions include:

GitHub can be used as a deployment source.

Application Insights

Azure Monitor

Integrated with App Service.

Provides monitoring data for Applications, Containers, VMs, and "Monitoring Solutions".

Can be integrated with Power BI.

Metric Analytics and Log Analytics are available.

Alerts and Autoscale configurations can be triggered from Azure Monitor.

Can integrate with Logic Apps and Export APIs.

Quotas are also available for CPU, RAM, Bandwidth, and Storage.

App Service Runtime Logs

Logs available for:

Custom Insights Logging

Use .traceTrace() method to leverage this within the application code.

See subsection "Custom Application Insights Logging" from the learn.microsoft.com module for sample code.

Review 'package.json', 'start' script line for DEBUG setting. Express.js and Node.js support 'DEBUG' variable as a was to enable debug logging in the Web App.

App Insights in Azure Portal

Settings > Application Insights > View APplication Insights Data > Investigate > Failures

Tips

Right click your Web App in the Azure Extension and select "Browse App" to launch a Web Browser directly to your deployed app.

Restart the WebApp by right-clicking the App Service resource and select "Restart".

Resources

Deploy a Node.js and MongoDB Web App to Azure.

MSFT Azure NodeJS Server Samples Repository.

Return to conted index

Return to ROOT README