I recently had to add some npm modules to a “classic” Azure Mobile Service instance built on node.js.

(I say classic, which is accessed through the old portal, as opposed to the new Azure Mobile Apps, which is managed through the new portal. But the process to add npm modules will be more or less the same.)

As I was doing so, I thought to myself … “this would be a great idea for a Code Mill Minute”!

Mainly because the first time I had to add npm modules to an Azure Mobile Service I was stumped for a bit. (For a while, I really liked editing my JavaScript through the built in editor in Azure.) But it turns out it’s really an easy process.

So here we go with a step by step process:

  1. Log into, or create, an AMS instance.
  2. Once there, head on over to the “Configure” tab.
  3. There you will see a “Git Url” text box. Copy the contents of that guy.Azure Git Get
  4. Head on over to your favorite git manager and clone that repo. (I prefer using Visual Studio with Node Tools for Visual Studio installed. In fact, I’m giving a talk on introducing Node.js to .Net developers at That Conference, Monday August 10. You should go! End of shameless plug.)
  5. Once you have the repo cloned, you are now free to issue npm install commands, and have it grab your modules, update the node_module folder & package.json file.
  6. Start developing using the new goodness downloaded from npm!
  7. Commit and push your repo back to Azure

Please note … you do not … and I repeat, do not push the node_modules folder to Azure. Azure will take care of downloading all of the modules and dependencies for you… just like a good friend should!

As an extra bonus – if you don’t trust that Azure downloaded all the node modules, or if you just need to do some debugging for other reasons, you can always head over to the Kudo console. To get to Kudo – you just put “scm” to your mobile service’s domain name. For example: {your-service-name}.scm.azure-mobile.net. Hit the Debug tab in the header (doesn’t matter if you CMD or PowerShell for this), and then you’ll be able to browse your site’s directory and inspect the node_modules folder for yourself. Yay for cool tools!

Screen Shot 2015-08-05 at 11.31.57 AM

Adding npm modules to other node instances/sites/services in Azure is as simple as cloning the git repo (you may need to setup continuous deployment in order to enable git within your Azure site). Once there, clone it, edit it, push it. Simple!