Building and Deploying your First Azure Function with Node.js

I’ve been writing Azure Functions for a while and working with Node and thought it was time I took the plunge to get both of them working together.

To get started, you’ll want to have Node.js (because that’s what you’re building), VSCode (because that’s for coding), and the Azure Core Functions Tool Library (because that’s what’s going to let you debug).

Installation of Node and Azure Core Functions can be accomplished via a few commands;

npm install -g npm
npm i -g azure-functions-core-tools@4 --unsafe-perm true

Once you have that all done, you can go ahead and create your AZ function in Azure. In this example, I’m creating a very simple HttpTrigger to go along with it.

Setting up the Function

The configuration of my function was pretty basic.

Debugging the Function Locally

After you’ve created your HTTPTrigger, the next thing you want to do is download it to your workstation so you can begin to work on it. When doing this you only need the “Site Content”.

When you load it into VSCode for the first time, you might be prompted to set your project up for VSCode usage (which adds a vscode folder to your solution).

With Azure Core Function Tools installed, you can then make changes to your function and test it all out locally. If you do not have the AZ Core Function Tools installed, you will not be able to browse your services locally.

Deploying your Changes

Without using GIT (that’s for another post), you can deploy your changes to AZ simply by logging into Azure (using the VSCode Extension), navigating to your AZ Function and right-clicking on the function and clicking deploy.

When you do this, you will be prompted that any changes will overwrite what exists on the server as you will be deploying a package to the server.

Once completed, you can validate your changes have made it to the server either via the AZ Function URL or by clicking on using the Code/Test function (in this case I only changed the output text).

If you run into deployment challenges (like I did the first time) – check your authentication publishing settings on your service (under Configuration).

You most likely need to enable deployment of your files to your service (although I don’t recommend “All allowed” in your Production environment.