NodeJs: Deploy your NodeJs app on Azure for FREE
Let’s face it, we think of deploying our applications on cloud for FREE every time we are ready with a few features, be it to enable other applications to integrate with our APIs or to demo the features to our stakeholders.
When picking a cloud provider, Azure probably is alluring the most these days. It is increasingly gaining popularity and more and more businesses are adopting it for their cloud computing needs. Ease of usage, an array SaaS apps, great docs & IT support, comparatively cheaper, etc. are some of the reasons why it is growing at a higher rate that the other cloud providers.
This post will help you to deploy your NodeJs app on Azure for FREE.
Step#1: Login
Login/Signup to Azure. If you are new to Azure, you will get a 12 month free subscription using which you can access many azure services for free. Signup here.
Step#2: Create a Web App
Create a resource, select “Web App”. This is a PaaS offering from Azure which is a fully managed container service to host web applications. It essentially builds an image of your project and deploys using docker.
- Select/create(if you don’t already have) a subscription and a resource group. A resource groups is a groups of services that are billed together.
- Give a unique name to your Web App.
- Leave the publish as “code” and select the Runtime stack as the Node version you are developing your app on.
- Select the region as “East US” and change the SKU to ‘F1’ which is free to use (this will be the default option when you have the 12 month free subscription).
Step#3: Review + Create
Go to “Review + create” tab and hit “Create”.
The Web App Service will deploy a dummy Microsoft-Web-WebApp-Portal to your Web App.
Step#4: Create a NodeJs app
Create a NodeJs app. Here, I have created a project from the NestJs starter app and pushed to a Git repository. Changes I did to the starter app:
- I have updated the main.ts file to primarily listen to port from environment rather than a hard-coded 3000. This is because Azure Web App Service deploys an app container @ 8080 (through env.PORT) and binds to the docker.
I have updated the Hello controller to listen to ‘/hello’ instead of ‘/’.
PS: the appService.getHello() returns “Hello World!”.
Step#5: Deploy
Now we deploy, finally!! You can deploy your app through VS Code. This step requires you to install ‘Azure Tools’ extension in VS Code.
- Install ‘Azure Tools’ extension in VS Code.
- Login to your Azure account in the extension (will be initially prompted).
- Deploy to Web-App. This option will ask you to select a project directory, zip it and upload & deploy your project in the Web App.
Or alternatively, you can hook your Web App to a source-control repository branch and it will trigger a build automatically when code is pushed to the branch. To enable this, go to the deployment center of your Web App and connect to your source-control repository of your NodeJs app. Save.
Step#6: Verify
Once done, try the WebApp’s url to check if it deployed fine.