Post/Code

HomeAboutUsesNow

More Azure & Node.js.

  • When deploying Node.js to Azure, the default entry file is server.js.
  • Make sure to set the port in your app to something like: const port = process.env.port || 8000; so that Azure can use it's preferred port.
  • 2 ways to setup up Node.js on Azure:

    1. In a Virtual Machine
    2. In an App Service

Azure Virtual Machines

  • Virtual Machine: In the Azure Portal, select 'Virtual machines' and follow the prompts: e.g. Ubuntu, SSD + SSH public key for authentication
  • In iterm2/terminal: ssh-keygen -t rsa -b 2084
  • Remember your passphrase if you set one
  • Once setup: ssh username@IP.ADD.RES.S
  • I had trouble using a non-standard key, as such, I ended up using the default: rsa_id
  • Once logged in, run:

    sudo apt-get update
    sudo apt-get install nodejs
    sudo apt-get install npm
    
  • Then run: nodejs -v to check your version and if all is well. *On your local, install the Azure CLI via Homebrew:

    brew update 
    brew install azure-cli
    
  • A few commands to get you started:

    az -h 
    az vm -h
    az login
    az stop
    az deallocate
    az start
    az account set --subscription your-subcription-name
    az vm list --output-table
    az vm deallocate --name your-vm-name --resource-group your-resource-group
    
  • You can then setup Local Git as a deployment source to Azure.

    cd your-project
    git init
    git add .
    git commit -m 'First commit'
    git add remote azure http://the-azure-git-url.git
    git push azure master
    az webapp browse --name your-app-name --resource-group your-resource-group 
    
  • Once that is done, you can setup deployment slots as:

    az webapp -h
    az webapp deployment slot swap --slot your-slot-name --name your-app-name --resource-group your-resource-group-name
    

Azure App Service

  • az group create --location 'location-name' --name your-app-service-name
  • az appservice plan create --name your-app-service-name --resource your-resource-name --sku FREE
  • az webapp create --name your-app-name --resource-group your-resource-group-name --plan your-plan-name
  • az webapp deployment source config-local-git --name your-app-name --resource-group your-resource-group-name
  • Then connect your add your Azure git remote, add/commit and push.