A Step-by-Step Guide to Linking and Deploying a Node.js Web App to Azure App Services and Connecting it to an SQL Database
Published: 2023-05-21 22:31:49

Introduction:
In today's digital era, deploying web applications to the cloud has become increasingly popular due to its scalability and ease of management. Azure App Services, coupled with Node.js and an SQL database, offers a powerful combination for hosting and running your web applications. In this blog, I will walk you through the process of linking and deploying a Node.js web app to Azure App Services and connecting it to an SQL database.

Prerequisites:
Before we begin, make sure you have the following prerequisites in place:

An Azure account: Sign up for an Azure account at [click](https://azure.microsoft.com).
Node.js and npm: Install Node.js and npm on your local machine. You can download them from [click here](https://nodejs.org).
Azure CLI: Install Azure CLI on your machine. You can find installation instructions at https://docs.microsoft.com/cli/azure/install-azure-cli.

**Step 1: Create an Azure App Service**

Log in to the Azure portal [click here](https://portal.azure.com) using your Azure account credentials.
Click on "Create a resource" and search for "App Service."
Select "Web App" from the search results and click "Create."
Provide a unique name for your app, choose your preferred subscription, resource group, and operating system.
Configure the runtime stack to Node.js and choose the desired version.
Click "Review + Create" and then "Create" to provision the App Service.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t9l4l2esgqs2jpkq75p0.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o13vktzctolaa4acoigj.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yn2bkgnveg05k4agq1ng.png)

Step 2: Set up your Node.js Web App

Open a terminal or command prompt and navigate to your project's directory.
Initialize a new Node.js project by running the command: npm start.
Install the necessary dependencies for your web app using npm run build.
Test your application locally using the command: npm run start. I am using windows, so this will open on local host 3000.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r14muyzjqo75jqalddju.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k871mwv36jbjpdieu81x.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9mh0wxm4ec4h0ix8ed84.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vhrn5x7ym5po03o1tysw.png)


Step 3: Connect to an SQL Database

In the Azure portal, go to your App Service's "Overview" page.
Under "Settings," click on "Configuration."
Add a new connection string by clicking on the "New connection string" button.
Enter a name for the connection string and select the SQL database provider.
Provide the necessary details, including the server name, database name, username, and password.
Click "OK" to save the connection string.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2fzu6dncn8u2xojvcp27.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2wky7rftpnbja28sswlq.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zuw6gtx01luwo5dsksj9.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qon3azek9qsqws4hlwzz.png)

Step 4: Deploy the Node.js Web App to Azure

In the Azure portal, navigate to your App Service's "Overview" page.
Under "Deployment," select "Deployment Center."
Choose the deployment method that suits your project (e.g., Local Git, GitHub, Bitbucket, etc.).
Follow the instructions to link your repository and configure the deployment settings.
Once configured, trigger a deployment to deploy your Node.js web app to Azure.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qr7xdpy4s0w4hbosuej0.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qu79n82z1iyo2258dmg3.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b4zdzmh591jnkcefy7zk.png)
Step 5: Verify and Test

Once the deployment is complete, navigate to your Azure App Service's URL.
Test your web app's functionality and ensure that it connects to the SQL database successfully.
Monitor the application's logs and Azure portal's metrics to ensure everything is running smoothly.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/topm0h5od82v4x6z7cxx.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dpbq8k481ytrwxd0q9uy.png)

Conclusion:
In Summary, we have explored the process of linking and deploying a Node.js web app to Azure App Services and connecting it to an SQL database. By following these steps, you can take advantage of Azure's robust infrastructure and scalability, allowing you to focus on building and maintaining your application without worrying about the underlying infrastructure.