Microsoft Azure Stack is an extension of Azure – bringing the agility and innovation of cloud computing to your on-premises environment and enabling the only hybrid cloud that allows you to build and deploy hybrid apps anywhere. We bring together the best of the edge and cloud to deliver Azure services anywhere in your environment.

Announcing Node.js support for Azure Mobile Apps

Last month, we announced significant update to the Mobile Apps feature of Azure App Service, which enabled developers to quickly build mobile backend APIs in .NET, add mobile features to their existing ASP.NET web apps, as well as add web pages to their .NET mobile backends.

Today we are releasing a Node SDK for Azure Mobile Apps, extending similar experience to Node.js apps. This enables you to build and run mobile backends using Node.js on App Service, as well as add push notifications, mobile auth, offline sync and other mobile features and backend APIs to any Node.js app running on App Service.

Using Azure Mobile Apps Tables

Mobile App Tables is a layer on top of your data store that allows the Azure Mobile Apps clients to access your application's data. Today we support Azure SQL DB and SQL Server for production applications. We've also included an in-memory store which shouldn't be used for production purposes, but can be convenient for demos and development purposes. When you add a table to your Mobile App on the first request, the SDK will create, in the case of SQL Server, a table. The table will have some important columns for the SDK like the id and a timestamp. It will also have any columns specified in the table definition, and if you have Dynamic Schema enabled, it will also add any columns included in the body, but not in the table already.

While being able to add a table with a single line of code is pretty cool, what if we want to customize the CRUD operations? There is a handy table configuration object to make that easy. Best practice is to define this in a separate file in a ./tables directory, so we'll create a TodoItem.js file.

There is support for the four classic CRUD operations with corresponding methods named insert, read, update, delete. Read more about the table operations in our API Documentation.

The context object exposes different properties depending on the operation; read expose a query object and insert and update expose an item object. These allow you to modify the behavior of the CRUD operation from the default.

If you haven't specified a database in your app settings (which the portal will help you do), it will use an in-memory store which should not be used for production purposes. Currently, the SDK only supports SQL Server, but we're investigating other options and we're open to contributions in this area. Visit our GitHub page to learn about setting up local environment variables to enable SQL locally.

Using auth with Azure Mobile Apps and node

Your next question is probably related to that context.user object. How does it get there? It's part of Azure Mobile Apps integrated authentication features. To learn more about how to set up auth, you can follow our Getting Started with Auth tutorial. Once you've done that, you can require authentication for a given table action with the following code.

table.insert.authorise = true;

If you want the whole table secured, use:

table.authorise = true;

Setting up auth to work locally requires a few extra steps we'll cover later on.

Feedback and thanks

A special thanks goes out to all the community members who have helped us with early feedback prior to this release. We'd like to encourage all of our users to provide any feedback you have on the product or experience of using it. Feel free to leave an issue on our GitHub for any bugs or new features.

Push will be coming soon and we'll have more blogs and documentation coming too as we keep fleshing out the SDK prior to release. So keep an eye out and start building some apps!