Share via


How to upload Node Packages to Azure Mobile Services

  1. Node.js applications uses packages to add functionality

  2. You can think of these as libraries

  3. The goal of this post is to show you how to upload these packages up to Azure Mobile Services so that you can give your node code more power

  4. This post is about adding QueryString to Azure Mobile Services.

SmartDoor Client on Github - Mono-based C# Raspberry PI Client https://github.com/sedouard/SmartDoorDemo
Raspberry Pi - Basic hardware setup, Plugging in camera, Connecting GPIO breakout, Closing up case https://stevenedouard.com/wiring-raspberry-pi-send-photos-cloud/
Running code on your Raspberry Pi to Send Photos the Cloud https://stevenedouard.com/running-code-raspberry-pi-send-photos-cloud/
How to upload Node Packages to Azure Mobile Services https://blogs.msdn.com/b/brunoterkaly/archive/2014/06/18/how-to-upload-node-packages-to-azure-mobile-services.aspx#
How To Provision A Shared Access Signature That Allows Clients To Upload Files To To Azure Storage Using Node.js Inside Of Azure Mobile Services https://blogs.msdn.com/b/brunoterkaly/archive/2014/06/13/how-to-provision-a-shared-access-signatures-that-allows-clients-to-upload-files-to-to-azure-storage-using-node-js-inside-of-azure-mobile-services.aspx#
Running .net Applications On A Raspberry Pi That Communicates With Azure https://blogs.msdn.com/b/brunoterkaly/archive/2014/06/11/mono-how-to-install-on-a-raspberry-pi.aspx#
Using Fiddler and Advanced Rest Client to test Azure Storage and Azure Mobile Services https://blogs.msdn.com/b/brunoterkaly/archive/2014/06/18/using-fiddler-and-advanced-rest-client-to-test-azure-storage-and-azure-mobile-services.aspx

DOWNLOAD THE GIT CLIENT FOR WINDOWS

  1. You will need a GIT client.

  2. Git is a distributed revision control and source code management (SCM) system with an emphasis on speed.

  3. Git was initially designed and developed by Linus Torvalds for Linux kernel development in 2005.

  4. We will need Git in order to be able to add node packages to Azure mobile services

    image001

    Figure 1: Downloading the Windows Git Client

  5. You can download it here: https://git-scm.com/download/win

  6. Once you install, consider a reboot.

DOWNLOADING THE NODE.JS APPLICATION FROM AZURE MOBILE SERVICES

  1. Your first goal is to download the Node.js code and packages down to your local machine

  2. You will then modify the package package.json, which contains a list of packages that need to be installed into Azure Mobile Services.

  3. You can't just copy packages directly. You must use Git to copy packages Azure mobile services

GETTING THE GIT ENDPOINT FROM AZURE MOBILE SERVICES

  1. Azure Mobile Services directly supports git.

  2. Navigate to the Azure Portal

  3. Select Mobile Services

  4. Select the CONFIGURE menu

    image002

    Figure 2: Getting to the Git URL from Azure Mobile Services

COPY THE URL TO THE CLIPBOARD

Once you copy the url to the clipboard, proceed to the next step.

OPENING A COMMAND PROMPT

  1. You will need to open a command prompt

  2. Type in git clone [ your git url from the

    image003

    Figure 3: Cloning the repository to your local computer

VIEWING THE RESULTS

  1. You will need to provide a user name and password

    image004

    Figure 4: What your screen should look like

  2. Now if you take a look at the c:\IoT folder (the one I am using), you will see the following:

    image005

    Figure 5: Viewing the folder structure of the cloned repository

  3. Now navigate to the raspberrypiservice  folder. Yours will be different. You defined it when you created your Azure Mobile Service.

  4. Navigate into the service folder and view the files

    image006

    Figure 6: Moving to the service folder (to see package.json)

  5. You can see the package.json file.

  6. This is the key file to edit.

MODIFY THE PACKAGE.JSON FILE

  1. Now you will need to modify the package.json file to include new node packages.

  2. For example purposes, we will include the packages qs (QueryString)

    • QS is a query string parser for node and the browser supporting nesting

WHAT PACKAGE.JSON LOOKS LIKE

  1. We need to modify the dependencies section of package.json.

  2. We will add qs there

    image007

    Figure 7: Viewing the package.json file

HERE IS THE FINISHED PRODUCT

  1. Notice the qs is now part of dependencies

    image008

    Figure 8: Adding qs (querystring) as a dependency

  1. Save and close the package.json

Commit the changes

  1. You will need to commit the changes before you push them up to the portal.

  2. The command is, git commit .

    image009

    Figure 9: Commiting the changes

  3. You will be asked to enter in a commit comment. Seen in yellow below.

    image010

    Figure 10: Adding a comment for the changes

  4. In the editor VI, you w ill hit w follow ed by q .

PUSHING OUR CHANGES BACK UP TO AZURE MOBILE SERVICES

  1. Now we will push our changes upstream.

  2. The command for this is simple: git push [remote-name] [branch-name] .

  3. But we want to push our master branch to the origin server (Azure Mobile Services)

  4. We will push our work back up to Azure Mobile Services with this command:

    • $ git push origin master

    image011

    Figure 11: Pushing the changes back up to Azure Mobile Services

MISSION ACCOMPLISHED OF THE NODE PACKAGE ADDED TO AZURE MOBILE SERVICES

  1. We completed what we set out to do

  2. We have added the node package qs to our Azure Mobile Services

UPDATE OUR NODE CODE TO USE THE NEW PACKAGE

  1. We will now make use of the **qs ** package in node.js

    image012

    Figure 12: Adjusting the node.js code to use qs (Query String Package)

  2. As you can see in the figure above, we are now able to leverage the node package known as qs .