How to publish your Node.js Application to Microsoft Azure

Navneet Saluja
The Startup
Published in
5 min readJun 24, 2020

Microsoft Azure is a cloud platform which has a lot of configuration to meet the needs of every developer. At the same time, it may be difficult for a person who is new to Azure to host their application on Azure. In this article, we will learn how to deploy a simple NodeJs application on Azure.

Prerequisites:

  • An Azure account. If you do not have an Azure account, you can register for free here. You can also avail a student developer discount here.
  • A NodeJs application. It can be simple or complex, it does not matter. I made a simple application which demonstrates the REST API. You can clone the code from this repository.
  • A GitHub account linked to your Microsoft Azure profile. The Nodejs application should also be made as a repository on GitHub. Learn how to connect your GitHub with your Azure account here.

Steps:

  1. Go to the Microsoft Azure website and log in to your account. Then go to https://portal.azure.com/. You should Azure Services on your screen.
  2. Click on Create a Resource and then search for “Web App.” The following screen should pop up:

3. Click on Create and a page shows up requesting you to enter the required Project details.

In the Subscription field, enter the Subscription with which you want to create this resource. For example, in my case I’m using the Azure for Students subscription.

Resource Groups are a collection of logical containers and it can be used to control all the members collectively at one time. If you have an existing resource group, use that or you can click the ‘Create new’ button and give it any name you want. In my case, I have named it node-express-resource-group since I won’t use it for any application which does not use Nodejs,

In the Instance Details part, enter the domain name at which you want your application to be hosted. For a beginner, publishing using Code instead of a Docker container is recommended. Runtime Stack should be whichever language and its version which we are using in our code, which is Nodejs and in my case the version is Node 12 LTS. Operating system should be Linux and feel free to choose whichever region of the world you want your website to be hosted in. I have chosen the Japan East region.

The App Service Plan fields are entirely upto you, choose whatever plan which suits you as per the demand and the load on the site. I have chosen the Basic B1 plan as I don’t plan on having more than a few visitors on my site.

All in all, the Basics tab of the Web App should look similar to this:

All the tabs after Basic, that are the Monitoring and the Tags tab have their values set by default so you do not need to change anything in them. In future, when you are better versed with Azure and its boatload of features you can always come back and edit them.

4. Click on the Review & Create tab and your Web App will be created. If it does not get created and shows an error, try changing the region in which you are deploying the website and try again, since the particular plan which you want might not be available in the region.

5. After the Web App gets created, go to its Overview page. If you cannot find the page, go to Home (that is the homepage of the Azure portal), open the sidebar and click on “All Resources”. Click on the name which has the Type as “App Service” and the following page is loaded:

6. Now, we’ll actually deploy our Nodejs application onto the site using GitHub. Go to the Deployment Center (under the Deployment tab in the left sidebar). Click on GitHub under Continuous Deployment.

7. In the next step you have to choose a Build Provider. The easiest way to deploy is using the Kudu App Service engine. Therefore, we’ll go ahead with that.

8. Then you choose the name of the Organization under which the GitHub repository is there, select the repository which you want to deploy and the Branch. Master is not supposed to be deployed in production applications, however since this is a just a beginner walkthrough, we’ll use the Master branch.

9. Give it a few minutes and once the Status display ‘Success(Active)’, your website has been deployed. Go to the overview tab and click the URL and enjoy your website!

A problem which I faced was the application taking too long a time to load on the Azure server. This was because when I was testing my application on my local machine, in the index.js or the app.js file you use the hostname as localhost and the port as 3000. However, when hosting on a cloud server you need to change those constants. You have to change it the hostname to process.env.HOST and the port to process.env.PORT. The deploying server part in your index.js or app.js file should now be similar to the following:

If you have reached here, congrats on deploying your Nodejs application to a cloud server which anyone can visit! Azure is a big platform for all your Cloud computing needs, feel free to explore more of this amazing service.

--

--