Skip to content

Instantly share code, notes, and snippets.

@georgeOsdDev
Created November 25, 2022 17:25
Show Gist options
  • Save georgeOsdDev/9eaf0775e17a6b8656ee3374355697b3 to your computer and use it in GitHub Desktop.
Save georgeOsdDev/9eaf0775e17a6b8656ee3374355697b3 to your computer and use it in GitHub Desktop.
How to use custom Node version on Azure App Service Linux
#!/bin/bash
# Usage
# 1.Save this file to project root directory
# 2.Defaul POST_BUILD_COMMAND in appsettings
# https://learn.microsoft.com/en-us/azure/app-service/configure-language-nodejs?pivots=platform-linux#customize-build-automation
# > az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings POST_BUILD_COMMAND="postbuild.sh"
# 3.Enable remote build
# https://github.com/projectkudu/kudu/wiki/Configurable-settings#enabledisable-build-actions
# 4.Update start script to use LTS binary instead of default Node.
# LTS binary path is defined in /home/site/lts_node_path
# "scripts": {
# "start": "NODELTS=`cat /home/site/lts_node_path`; echo 'Run app with' && ${NODELTS} -v; ${NODELTS} dist/node/index.js",
# },
# 5.Push to Azure
# Install NVM to /home.site/.nvm
cd /home/site/
export NVM_DIR=/home/site/.nvm && (
git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR"
cd "$NVM_DIR"
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
) && \. "$NVM_DIR/nvm.sh"
# Install node lts
nvm install --lts
# Find executable node path
echo `nvm which current` > /home/site/lts_node_path
# Use LTS Node binary with NPM start script
#
# "scripts": {
# "start": "NODELTS=`cat /home/site/lts_node_path`; echo 'Run app with' && ${NODELTS} -v; ${NODELTS} dist/node/index.js",
# },
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment