mobile

Adding database support for local Azure Mobile App with Node.js

Microsoft Azure Mobile Apps have support for node.js. You can easily clone the app backend to your local machine and test / debug your application there instead of deploying it to Azure on each change. Database support for your local copy can be achieved using a special file called azureMobile.js in your projects root folder as you can read in the holy bible of Azure Mobile App with Node.js.

As you can see in the data part of the configuration it says “mssql” as the desired platform. I don’t know if there is any support for other platforms, but looking in the documentation and the code I could not find any.

Unfortunately as a mobile developer participating in many iOS related projects I work on Mac OS X which lacks support for MS-SQL Server. So why not use Microsoft Azure itself?  Create a new SQL database (or use your existing one if you like), add your credentials like shown in the Gist, start your local app aaaaaand ….. your app will crash silently.

An Azure Database Server instance allow only local connections by default. You can add an exception for your development machine by selecting “All ressources” -> Your SQL Server -> “Firewall” -> And “Add Client IP” in the Azure Portal.

This is an adequate option for an app still in development, but please don’t use this in production mode. You should consider adding a second SQL Server instance for that case. One last advice: Don’t add azureMobile.js to your versioning system.

Firewall settings for an Azure SQL Database.

Firewall settings for an Azure SQL Database.

Summary:

  1. Create azureMobile.js in your projects root folder
  2. Create a second database-(server) for development in Azure and add the credentials to your azureMobile.js
  3. Adjust the servers firewall settings to allow access for your local development machine
  4.  Make sure azureMobile.js is ignored by your versioning system (e.g. add it to .gitignore)

 

Standard