A small gotcha with NodeJS Application settings on Azure that can surprise you

The following code runs perfectly fine on a NodeJS server that’s hosted outside of Azure App Services:

During development, running NodeJS on a local server, the environment variable API_AI_ACCESS_TOKEN are set in package.json file. Just for completeness, let me show the constants.js file, since it only takes a few lines:

On Azure, the environment variables such as API_AI_ACCESS_TOKEN has to be set in the Application Settings blade. That’s the UI way of doing it. We can also set it using a command line. Either way, the setting of environment variable has to be done first.

But even then, when we try to access the web application, it gives an error page that looks something like

iisnode encountered an error when processing the request.

HRESULT: 0x6d
HTTP status: 500
HTTP subStatus: 1013
HTTP reason: Internal Server Error

IIS? What is that? If this is the first time you try to deploy your app on Azure, you might not feel so “pressured”. But in my case, my app used to work just fine in production. Suddenly, nothing works anymore on Azure and there’s no console to look at, like on my local server.

Here’s a good resource that helped me out:

Long story short, the fix is extremely simple. Simply restructure the code as follow:

Driven by passion and patience. Read my shorter posts https://dev.to/codeprototype (possibly duplicated from here but not always)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store