Cloud and deployment · Intermediate · 22 min
Deploy a Node.js app to Azure App Service with Bicep
By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · Azure CLI 2.93.0 · Bicep 0.49.2 · App Service runtime NODE|26
You will describe a Linux App Service plan, a Node.js 26 web app and a staging slot in one Bicep file, lint and preview it, ship two versions of a small app as zip packages, swap staging into production and then delete everything.
On this page
Azure App Service runs a web app for you: you hand it code, it gives you an HTTPS address, patches the operating system and the Node.js runtime, and restarts the app when it crashes. You can set it up by clicking through the portal, but then nobody can review the setup or rebuild it the same way. Bicep is Azure's own infrastructure-as-code language. You describe the resources in a .bicep file, the Azure CLI compiles it to an ARM template, and Azure Resource Manager makes your subscription match.
In this tutorial you build one small, complete setup in ~/azure-node-demo:
- a Node.js app with no dependencies that reports its version and which slot it runs in
- a Bicep file for a Linux App Service plan, a web app on the Node.js 26 runtime with HTTPS only, a system-assigned managed identity, app settings, and a
stagingdeployment slot - a linter configuration that turns three common mistakes into errors
You then preview the change with what-if, deploy it, release version 1.0.0 to production and 1.1.0 to staging, swap the slots, roll back, and delete the resource group. The first four steps need no Azure account. The rest do, and the plan they create bills while it exists.
Step 1 · Install the Azure CLI and Bicep
Microsoft publishes the Azure CLI as an apt package for Ubuntu 26.04 (codename resolute). Install the tools the repository setup needs, plus Node.js, zip and jq, which you use later:
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg lsb-release nodejs zip unzip jq libicu-devlibicu-dev brings in the ICU library that the Bicep program (a .NET application) uses for text handling. Ubuntu's own nodejs package is fine for running the app locally, since it uses only built-in modules.
Add Microsoft's signing key and the Azure CLI repository, then install version 2.93.0 exactly:
sudo mkdir -p /etc/apt/keyrings
curl -sLS https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /etc/apt/keyrings/microsoft.gpg > /dev/null
sudo chmod go+r /etc/apt/keyrings/microsoft.gpg
AZ_DIST=$(lsb_release -cs)
printf 'Types: deb\nURIs: https://packages.microsoft.com/repos/azure-cli/\nSuites: %s\nComponents: main\nArchitectures: %s\nSigned-by: /etc/apt/keyrings/microsoft.gpg\n' "$AZ_DIST" "$(dpkg --print-architecture)" | sudo tee /etc/apt/sources.list.d/azure-cli.sources
sudo apt-get update
sudo apt-get install -y "azure-cli=2.93.0-1~${AZ_DIST}"
az versionThe Azure CLI downloads and manages its own copy of the Bicep program. Pin it too, so a new Bicep release cannot change what your file compiles to without you noticing:
az bicep install --version v0.49.2
az bicep versionLater updates come through sudo apt-get install --only-upgrade azure-cli and az bicep upgrade. Pinning means you run those on purpose, read the release notes, and recompile.
Check it worked
az version prints JSON with "azure-cli": "2.93.0". az bicep version prints a line starting Bicep CLI version 0.49.2.
Step 2 · Write the Node.js app
Make the project folder with an app folder for the code. Everything in app goes into the zip package, and nothing else does:
mkdir -p ~/azure-node-demo/app
cd ~/azure-node-demo/appThe app answers / with a small JSON document and /health with ok. App Service tells a Node.js app which port to listen on through the PORT environment variable, so the code reads it and falls back to 3000 on your machine. The version comes from package.json, so it travels with the code. The slot name comes from an app setting you will define in Bicep:
cat > server.js <<'JS'
const http = require('node:http');
const { version } = require('./package.json');
const port = Number(process.env.PORT) || 3000;
const slot = process.env.APP_SLOT || 'local';
const server = http.createServer((req, res) => {
if (req.url === '/health') {
res.writeHead(200, { 'content-type': 'text/plain' });
res.end('ok\n');
return;
}
res.writeHead(200, { 'content-type': 'application/json' });
res.end(JSON.stringify({ app: 'azure-node-demo', version, slot }) + '\n');
});
server.listen(port, () => console.log(`azure-node-demo ${version} listening on ${port}`));
JS
cat > package.json <<'JSON'
{
"name": "azure-node-demo",
"version": "1.0.0",
"private": true,
"engines": { "node": ">=26" },
"scripts": { "start": "node server.js" }
}
JSONThe engines field records the runtime you deploy to. Your local Node.js can be older; the app uses nothing newer than node:http.
Start it in this terminal:
node server.jsIn a second terminal, call it:
curl -s --retry 10 --retry-connrefused --retry-delay 1 http://localhost:3000/
curl -s http://localhost:3000/healthStop the server with Ctrl+C in the first terminal when you have seen the output.
Check it worked
The first curl prints {"app":"azure-node-demo","version":"1.0.0","slot":"local"} and the second prints ok. The server's terminal shows azure-node-demo 1.0.0 listening on 3000.
Step 3 · Describe the plan, the app and the slot in Bicep
Go back to the project folder and create main.bicep. Read it once from top to bottom before you save it; the notes below explain the parts that matter:
cd ~/azure-node-demo
cat > main.bicep <<'BICEP'
@description('Short lowercase name used in every resource name.')
@minLength(3)
@maxLength(12)
param prefix string
@description('Azure region for all resources. Defaults to the resource group region.')
param location string = resourceGroup().location
@description('App Service plan size. Deployment slots need Standard (S) or Premium (P).')
@allowed([
'S1'
'P0v3'
'P1v3'
])
param skuName string = 'S1'
var suffix = uniqueString(resourceGroup().id)
var planName = 'plan-${prefix}-${suffix}'
var appName = 'app-${prefix}-${suffix}'
var siteConfigBase = {
linuxFxVersion: 'NODE|26'
appCommandLine: 'node server.js'
alwaysOn: true
ftpsState: 'Disabled'
minTlsVersion: '1.2'
http20Enabled: true
healthCheckPath: '/health'
}
resource plan 'Microsoft.Web/serverfarms@2024-11-01' = {
name: planName
location: location
kind: 'linux'
sku: {
name: skuName
}
properties: {
reserved: true
}
}
resource app 'Microsoft.Web/sites@2024-11-01' = {
name: appName
location: location
kind: 'app,linux'
identity: {
type: 'SystemAssigned'
}
properties: {
serverFarmId: plan.id
httpsOnly: true
clientAffinityEnabled: false
siteConfig: union(siteConfigBase, {
appSettings: [
{ name: 'APP_SLOT', value: 'production' }
{ name: 'NODE_ENV', value: 'production' }
{ name: 'SCM_DO_BUILD_DURING_DEPLOYMENT', value: 'false' }
]
})
}
}
resource staging 'Microsoft.Web/sites/slots@2024-11-01' = {
parent: app
name: 'staging'
location: location
kind: 'app,linux'
identity: {
type: 'SystemAssigned'
}
properties: {
serverFarmId: plan.id
httpsOnly: true
clientAffinityEnabled: false
siteConfig: union(siteConfigBase, {
appSettings: [
{ name: 'APP_SLOT', value: 'staging' }
{ name: 'NODE_ENV', value: 'production' }
{ name: 'SCM_DO_BUILD_DURING_DEPLOYMENT', value: 'false' }
]
})
}
}
resource stickySettings 'Microsoft.Web/sites/config@2024-11-01' = {
parent: app
name: 'slotConfigNames'
properties: {
appSettingNames: [
'APP_SLOT'
]
}
}
output appName string = app.name
output productionUrl string = 'https://${app.properties.defaultHostName}'
output stagingUrl string = 'https://${staging.properties.defaultHostName}'
output principalId string = app.identity.principalId
BICEPWhat the file says:
- Names.
uniqueString(resourceGroup().id)gives a stable 13-character hash, so the app name, which must be unique across all of Azure because it becomes<name>.azurewebsites.net, does not clash with anyone else's. The same resource group always gives the same names, which is what makes a rerun update instead of duplicate. - The plan is the set of machines your apps run on, and what you pay for.
kind: 'linux'withreserved: truemakes it a Linux plan.skuNameonly allows Standard and Premium sizes, because only those have deployment slots. - The runtime.
linuxFxVersion: 'NODE|26'picks App Service's built-in Node.js 26 LTS image.appCommandLinestarts the app directly instead of relying on App Service guessing the start file. - HTTPS only.
httpsOnly: trueredirects plain HTTP to HTTPS,minTlsVersionrefuses old TLS, andftpsState: 'Disabled'turns off FTP uploads, which you do not need. - Managed identity.
SystemAssignedgives the app its own identity in Microsoft Entra ID, with no password stored anywhere. On its own it can do nothing; it becomes useful when you grant it a role, for example to read secrets from Key Vault. The slot has its own identity, because identities stay with their slot when you swap. - App settings reach your code as environment variables.
SCM_DO_BUILD_DURING_DEPLOYMENTset tofalsetells App Service to run the zip as it is. An app with npm dependencies either shipsnode_modulesin the zip or sets this totrueso App Service runsnpm installafter upload. - The slot is a second live copy of the app on the same plan, with its own address.
slotConfigNamesmarksAPP_SLOTas sticky: on a swap the code and the other settings move, butAPP_SLOTstays with the slot it was set on. That is how the app can always tell you where it is running.
Never put a password, connection string or API key in this file or in the app settings list as a literal. Keep secrets in Key Vault and let the managed identity read them, or pass them as @secure() parameters from an environment variable at deploy time.
Check it worked
grep -c "^resource " main.bicep prints 4: the plan, the app, the slot and the sticky-settings configuration.
grep -c "^resource " main.bicepStep 4 · Lint and compile the file
Bicep ships with a linter. Its default rules mostly warn; you can raise the ones you care about to errors in a bicepconfig.json next to the file. These three catch leftovers from editing, a parameter or variable that nothing uses, and a region typed into a resource instead of passed as a parameter.
cat > bicepconfig.json <<'JSON'
{
"analyzers": {
"core": {
"enabled": true,
"rules": {
"no-unused-params": { "level": "error" },
"no-unused-vars": { "level": "error" },
"no-hardcoded-location": { "level": "error" }
}
}
}
}
JSONLint the template, then compile it to the ARM JSON that Azure Resource Manager actually receives:
az bicep lint --file main.bicep
az bicep build --file main.bicep
jq -r '.resources[].type' main.json | sortSee the linter do its job. Make a copy of the file with a parameter nothing uses, and lint the copy:
mkdir -p lint-demo
cp bicepconfig.json lint-demo/
{ cat main.bicep; echo "param leftover string = 'unused'"; } > lint-demo/main.bicep
az bicep lint --file lint-demo/main.bicep > lint-demo/result.txt 2>&1 || echo "lint found a problem"
grep "no-unused-params" lint-demo/result.txt
rm -rf lint-demoaz bicep build refuses to compile a file with error-level findings, so the same rules guard every deployment, not only the lint run.
Check it worked
The lint of main.bicep reports no errors (a notice that a newer Bicep release exists is fine). jq lists Microsoft.Web/serverfarms, Microsoft.Web/sites, Microsoft.Web/sites/config and Microsoft.Web/sites/slots. The broken copy prints lint found a problem and a line with Error no-unused-params: Parameter "leftover" is declared but never used, or something very like it.
Step 5 · Sign in, pick a region and preview with what-if
From here on you work against Azure. Sign in; the CLI opens a browser, or prints a code to type at a Microsoft page if you are on a server with no browser:
az login
az account show --query "{name:name, id:id}" -o tableIf you have more than one subscription, choose the sandbox one with az account set --subscription "<subscription name or id>" (replace the placeholder).
Check that the Node.js 26 runtime is on offer, since App Service adds and retires runtimes over time:
az webapp list-runtimes --os linux | grep NODEThe list includes NODE:26 (and older lines such as NODE:24). If 26 is missing, use the newest one listed and change linuxFxVersion to match, for example NODE|24-lts.
Pick a region. Users in Southern and East Africa are usually served best from South Africa North (southafricanorth, Johannesburg), which has three availability zones. If most of your users are in West or North Africa, compare it with Europe regions such as westeurope or francecentral. Fewer network hops matter most for people on mobile data. Set the names once for this terminal:
RG=rg-azure-node-demo
LOCATION=southafricanorthCost. The Standard S1 plan in this template bills for every hour it exists, whether or not anyone visits the app. Check the price for your region on the App Service pricing page before you continue, and finish the clean-up step when you are done. The Free (F1) tier costs nothing but, as of 26 November 2026, gives 60 CPU minutes a day, 1,024 MB of memory and 1 GB of storage per plan, has no Always On, no custom-domain TLS and no deployment slots, so this template does not allow it. Basic (B1) has no slots either; Standard has five.
Create the resource group, then ask Azure what the deployment would change without changing anything:
az group create --name "$RG" --location "$LOCATION"
az deployment group what-if --resource-group "$RG" --template-file main.bicep --parameters prefix=nodedemoCheck it worked
az group create prints JSON with "provisioningState": "Succeeded". The what-if output marks the plan, the site, the staging slot and the slotConfigNames configuration with + Create, and ends with a summary along the lines of Resource changes: 4 to create. Nothing in your subscription has changed yet.
Step 6 · Deploy the template
Run the deployment. It uses the same file and parameters as the preview:
az deployment group create --resource-group "$RG" --name main --template-file main.bicep --parameters prefix=nodedemoIt takes one to three minutes. Read the outputs into shell variables:
APP=$(az deployment group show -g "$RG" -n main --query properties.outputs.appName.value -o tsv)
PROD_URL=$(az deployment group show -g "$RG" -n main --query properties.outputs.productionUrl.value -o tsv)
STAGING_URL=$(az deployment group show -g "$RG" -n main --query properties.outputs.stagingUrl.value -o tsv)
echo "$APP $PROD_URL $STAGING_URL"Run the same az deployment group create command again. Nothing new is created: Resource Manager compares the file with what exists and only applies differences. That is the habit to build: change the file, run what-if, then deploy.
Check it worked
The deployment ends with "provisioningState": "Succeeded". echo prints an app name like app-nodedemo-<hash> and two https:// addresses, the second ending in -staging.azurewebsites.net or a similar staging host name. Opening the production address in a browser shows App Service's default page, because no code is deployed yet.
Step 7 · Release 1.0.0 to production and 1.1.0 to staging
Package version 1.0.0. App Service expects the files at the top of the zip, not inside a folder, so zip from inside app:
cd ~/azure-node-demo/app
zip -r ../app-1.0.0.zip server.js package.json
unzip -l ../app-1.0.0.zipDeploy it straight to production for the first release. The CLI uploads the package, App Service unpacks it into /home/site/wwwroot and restarts the app:
cd ~/azure-node-demo
az webapp deploy --resource-group "$RG" --name "$APP" --src-path app-1.0.0.zip --type zip
curl -s "$PROD_URL/"Now make a new release. Rewrite package.json with the new version:
cd ~/azure-node-demo/app
cat > package.json <<'JSON'
{
"name": "azure-node-demo",
"version": "1.1.0",
"private": true,
"engines": { "node": ">=26" },
"scripts": { "start": "node server.js" }
}
JSON
zip -r ../app-1.1.0.zip server.js package.json
unzip -p ../app-1.1.0.zip package.json | grep '"version"'Deploy 1.1.0 to the staging slot only. Production keeps serving 1.0.0 while you test:
cd ~/azure-node-demo
az webapp deploy --resource-group "$RG" --name "$APP" --slot staging --src-path app-1.1.0.zip --type zip
curl -s "$STAGING_URL/"
curl -s "$PROD_URL/"Check it worked
unzip -l lists server.js and package.json with no folder in front of them, and the 1.1.0 package shows "version": "1.1.0". After the deploys, staging answers {"app":"azure-node-demo","version":"1.1.0","slot":"staging"} and production still answers {"app":"azure-node-demo","version":"1.0.0","slot":"production"}. The first request after a deploy can take several seconds while the app starts.
Step 8 · Swap staging into production, and roll back
A swap warms up the staging slot with production's sticky settings, then switches the routing, so visitors move to the new code without a gap. Always make production the target:
az webapp deployment slot swap --resource-group "$RG" --name "$APP" --slot staging --target-slot production
curl -s "$PROD_URL/"
curl -s "$STAGING_URL/"Production now runs 1.1.0 and still says production, because APP_SLOT is sticky. Staging holds the old 1.0.0 code. That is your rollback: if 1.1.0 misbehaves, run the same swap again and the previous release is back in production within a minute or so.
az webapp deployment slot swap --resource-group "$RG" --name "$APP" --slot staging --target-slot production
curl -s "$PROD_URL/"Settings such as HTTPS Only, the TLS version and the managed identities do not move in a swap; each slot keeps its own. That is why the Bicep file sets them on both.
Check it worked
After the first swap, production answers "version":"1.1.0","slot":"production" and staging answers "version":"1.0.0","slot":"staging". After the second swap, production is back on 1.0.0. The App Service activity log in the portal shows each swap as Swap Web App Slots.
Step 9 · Delete everything you created
Everything in this tutorial lives in one resource group, so deleting the group removes the plan, the app, the slot and both identities, and stops the billing. Check the name first, because the command deletes every resource in the group, including anything you added by hand:
az resource list --resource-group "$RG" --query "[].{name:name, type:type}" -o table
az group delete --name "$RG"The CLI asks Are you sure you want to perform this operation? (y/n):. Answer y only if the list holds nothing else you need. Then remove the local files:
cd ~
rm -rf ~/azure-node-demoCheck it worked
az group exists --name rg-azure-node-demo prints false once the deletion finishes, which can take a few minutes. ls ~/azure-node-demo reports that the folder does not exist. The Azure CLI and Bicep stay installed for the next tutorial.
Next steps
- Run the same Node.js app as a container that scales to zero when idle: run a container on Azure Container Apps, which also uses a managed identity to read Key Vault secrets.
- Package the app as an image first with write a Dockerfile for a Node.js app, then compare App Service with Google's equivalent in deploy a container to Google Cloud Run.
- If your team works across several clouds, read choose between Terraform and OpenTofu to see when a multi-cloud tool fits better than Bicep.
- Put
main.bicepandbicepconfig.jsonin Git and runaz bicep lintandaz bicep buildin CI on every pull request, so a broken template never reachesaz deployment group create.
Related tutorials
- Tag cloud resources so you know what costs whatYou will have a four-key tagging scheme applied to every AWS resource through Terraform default_tags, a script that lists resources missing a tag, a tag policy ready for your organisation and cost allocation tags that split the bill by project.
- Store and serve files with Cloudflare R2 from a WorkerYou will build a Worker that uploads, downloads and lists files in an R2 bucket, with a size limit, a content-type allowlist, ETag and range support and a bearer token, test it locally with Wrangler and Vitest, and reach the same bucket through R2's S3-compatible API.
- Store container images in Amazon ECR with scanning and lifecycle policiesYou will have a private Amazon ECR repository with immutable tags and scan on push, an nginx image copied into it with crane, its vulnerability findings read from the CLI, a lifecycle policy that keeps the ten newest tagged images, and pull access granted to a second AWS account.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials