Making a node.js Cloud Application in Azure

I solved my Heroku problem from yesterday. I’d added some new .env setting values but not copied them into the Heroku application. So when the app woke up on the server it instantly fell over because lots of things were not set properly. The app was soon working fine, but it did have one problem. Heroku turns an application off if it has not been used for a while. This is usually fine. It will be started next time someone visits the site. However, at the moment my app also monitors MQTT and registers devices when they connect, so I need to have it running all the time. You can stop an inactive app from being switched off, but this involves spending money on a paid service which, being a Yorkshireman, I’m not keen on.

Instead I thought I’d try hosting the application on Azure, where I have some credits (not that I expect it to cost a lot). I followed this tutorial (or at least the second half of it) and in no time at all I had something that didn’t work. Oh well. The error was interesting. Azure didn’t know where to start. I was a bit confused because exactly the same code was running fine on Heroku. It turns out that I needed to add a start element to the settings in package.json:

"scripts": {
    "devStart": "nodemon server.js",
    "start":"node server.js"
  },

I think that Heroku just finds the nearest .js file and runs it to start an application if one is not specified, whereas Azure is a bit more careful. Anyhoo, after this I now have a management interface for all my devices.

This is the control panel for one of my little boxes. I can modify the device settings, see when it was last connected and send it commands to do stuff.

It really is incredibly easy to make your own node applications and deploy them like this. If you don’t care about app timeouts you can build and deploy something entirely for free. The integration of the process in to Visual Studio is very impressive.

I put the app onto a paid subscription (around 10 pounds a month) and then twiddled the application settings to make it always on. Great fun.