Marcel
Marcel That's me: Marcel

Deploy a node.js script in seconds to an Azure Web App with git and run it server-less

Deploy a node.js script in seconds to an Azure Web App with git and run it server-less

Deploy a node.js script in seconds to an Azure Web App with git and run it server-less

In customer projects, I sometimes develop small applications to collect and process data from different data sources or to offer a web interface. In any case, I try to avoid rolling out a VM to run these apps. I strictly prefer using Platform-as-a-Service and it works nearly 100% if I use an Azure Web App or Azure Functions.

The advantages are obvious:

  • No patching of VM’s
  • No further infrastructure for VM’s
  • No monitoring of OS specific metrics
  • No additional monitoring solution
  • Not involved in release cycles for the operating system
  • And a lot more

In this post, I will describe how easy it is to deploy a node.js application with git to an Azure Web App. To make it more comprehensible I will describe it with a node.js game called “tanks” from @darthrubens. Tanks is a multi-player game developed in node.js.

Tools

Later in this post we will need a few tools to test the game locally and to upload it to an Azure Web App.

Install:

Create an Azure Web App

Create an Azure Web App in the Azure Portal with an App service plan (or use an existing one):

deploynodejsapp-01

deploynodejsapp-02

img

Use at least a standard pricing tier to enable apps to run permanently.

deploynodejsapp-04

img

false

Configuration of the Azure Web App (save it):

img

Get the publishing information (username and password) by downloading the profile:

deploynodejsapp-07

deploynodejsapp-08

Write down the username, password and the web app url for later.

Test the application locally (optional)

Extract the zip file from tanks to a folder, open a command line and navigate to this folder. At the very first time, you must install the packages and dependencies for the node.js application. Type:

npm install

To run the node.js application type:

npm start

The application starts and is accessible by this url: http://localhost:8082/

img

deploynodejsapp-10

Upload the node.js application to the Azure Web App

In this post, I use git to manage the source code and upload it to Azure. I recommend learning how to use git. It’s a very powerful tool. I only describe the necessary steps here.

First initialize your git project by typing:

git init

Add the files and directories to your local repository

git add *

Then commit all to git:

git commit -m "Init"

Add the web app as a remote repository (use your web app url and add scm after the host name):

git remote add azure http://deploy-an-app.scm.azurewebsites.net

And finally push your application (you will be asked for the username and password)

git push azure master

Hint: Git ignores node_modules folder. The modules will be installed by the Azure Web App based on the dependencies listed in packages.json

deploynodejsapp-11

deploynodejsapp-12

deploynodejsapp-13

deploynodejsapp-14

deploynodejsapp-15

Done

Your Azure Web App is now running your node.js application:

deploynodejsapp-16_0

First published on: https://www.sepago.de/blog/deploy-a-node-js-script-in-seconds-to-an-azure-web-app-with-git-and-run-it-server-less/