• 3 min read

Progress update: Node.js SDK for Azure App Service Mobile Apps

Back in September, we announced the availability of the first alpha release for the Node.js SDK for Azure App Service Mobile Apps. This blog post is an update to that and details the improvements we made in the last three months.

Back in September, we announced the availability of the first alpha release for the Node.js SDK for Azure App Service Mobile Apps. This SDK streamlines the code for implementing a mobile backend with Azure App Service. We've been hard at work since then developing the solution with plenty of real-world experience and feedback from the community.

Yeoman generator

The code to implement a simple mobile backend is relatively trivial, especially if you have experience developing web applications in Node.js. However, we wanted to make the process of producing the basic scaffolding even easier. The Node.js community has an excellent tool called Yeoman that produces scaffolding for projects and we've released a plugin for it. Use the following to set up a new Azure App Service Mobile Apps project:

npm install -g yo generator-azure-mobile-apps
mkdir myproject
cd myproject
git init
yo azure-mobile-apps

You may need to use sudo npm install -g on a Mac or Linux system. The project scaffolded includes support for offline sync enabled table controllers, API, Azure App Service authentication and authorization in addition to push notification registrations.

Offline development

We added configuration support for offline development. You will still need an Azure App Service configured with authentication to test authentication, but unauthenticated access to tables and APIs can be run on your local development environment and does not need to be uploaded to an Azure App Service to do so. Consult our documentation for instruction on setting up your local development environment.

The basic app template

During the development process, we noticed cases during a backend update where traffic could be served prior to the database being ready. This resulted in clients receiving a 404 or 500 error message. To alleviate this problem, we provided a Promise you can use to initialize the database prior to serving requests. This means the client will receive a timeout instead of an error. Most offline-capable mobile clients will try later in this case. The template now looks like the following:

var express = require('express')(),
    azureMobileApps = require('azure-mobile-apps');

var mobile = azureMobileApps();

// Import the files from the tables directory to configure the /tables API
mobile.tables.import('./tables');

// Initialize the database before listening for incoming requests
// The tables.initialize() method does the initialization asynchronously
// and returns a Promise.
mobile.tables.initialize()
    .then(function () {
        express.use(mobile);    // Register the Azure Mobile Apps middleware
        express.listen(process.env.PORT || 3000);   // Listen for requests
    });

Azure Mobile Apps home page

Some members of our community lamented the lack of a home page on an Azure Mobile Apps backend. We explicitly made the decision to remove the home page because you can now create a combined web and mobile application using the same table controllers for both. Since such an application would already have a home page, one was not needed in the backend. We've listened to you and returned the home page, but you have to enable it in your code:

var express = require('express')(),
    azureMobileApps = require('azure-mobile-apps');

var mobile = azureMobileApps({
    homepage: true
});

Authentication and Authorization updates

The latest release of the Azure Mobile Apps SDK for Node.js fully supports the Azure App Service Authentication and Authorization service. This service supports authentication via social logins (including Facebook, Twitter, Google and Microsoft), Azure Active Directory and custom authentication. Authentication is configured on a per-table basis.

var azureMobileApps = require('azure-mobile-apps');

// Create a new table definition
var table = azureMobileApps.table();

// Configure table options
table.dynamicSchema = true;
table.access = 'authenticated';

// Export the table definition
module.exports = table;

Place table definitions within the tables sub-directory and they will be automatically picked up by the mobile.table.imports() method.

More samples

We've added plenty of samples to our GitHub repository, including explicit examples for common scenarios.

We've also included a fully annotated example of our regular QuickStart backend that supports local development, offline sync and authentication.

Get involved

This SDK is still in beta and there is plenty of time to get involved. Join the conversation in our GitHub repository, file an issue in GitHub issues or chat with the developers on Gitter. If you run into problems, bring them up on Stack Overflow or the MSDN Forums.

Follow @AzureMobile on Twitter to hear news about Azure App Service Mobile Apps.