By Matthys November 30, 2020 In Uncategorized

Free Node.js hosting with Azure

Node.js

As defined on techterms.com, a recursive function that calls itself during its execution.Node.js allows the creation of Web servers and networking tools using JavaScript and a collection of “modules” that handle various core functionalities.

JavaScript is the only language that Node.js supports natively, but many compile-to-JS languages are available.

Azure

Microsoft Azure, commonly referred to as Azure, is a cloud computing service created by Microsoft for building, testing, deploying, and managing applications and services through Microsoft-managed data centers.

In this case, we will be using Azure “App Service” for the hosting of the application.
The “App Service” allows for the hosting of up to 10 services under the “Always Free” plan

Step by Step Guide

For the purpose of this guide it will be assumed that you already have experience in Node.js, and that you have already created your web application, hosted locally, that you would like to host online.

This guide will also make use of Visual Studio Code as code editor.

- Step 1: Create a Microsoft Account

Using any valid and accessible e-mail address, create yourself a Microsoft account here. This will be used to sign up for Azure in the next step.

- Step 2: Signup for Azure

Now that you have created your account, you can sign up for Azure here.

If you already have an account you can select it from the list above, otherwise add the newly created account.

You will be prompted for your banking details, but be rest assured that you wont be charged for anything concerning this guide.

- Step 3: Azure Tools in VS CODE

IF this is your first time using Azure in VS Code you will need to install the “Azure Tools” extension in VS Code.

- Step 4: Create Web App

Once the extension is installed, open your Node.js project in VS Code and head to the App Service toolbar on the Azure panel and sign in

The “+” will allow you to create a new web app. Give the app a unique name and select project directory you would like to use.

Wait for the project to be uploaded.

- Step 5: Done

At this point you should be able to see the web app uploaded on the panel and be able to access the web app from the given url.

Following I will discuss a few of the bumps in the process I’ve encountered and hopefully help you fix those if they occur.

- Bump 1: Start Script

Azure will make use of the “npm start” command, and you will therefor need to create a start script in your package.json file.

Or in the case of the server.js file being located in a subfolder.

“scripts”: {     “start”“node server.js”  },

 

“scripts”: {
    “start”“node {sub}/server.js”
  },

- Bump 2: Server Port

To run the server locally I originally set the express app to listen on a custom port, (5000 in my case), to avoid conflicts.

Azure makes use of port 8080, so ensure the port is adjusted to account for that.

 
app.listen(8080,()=>{});