Deploying Node.js to Azure

Home / Deploying Node.js to Azure

If you recall my previous post on Node.js, I explored developing a Node.js app with Visual Studio. Using this approach makes it very easy to deploy and test with Visual Studio directly to Azure. However, I wanted to work with a more cross-platform approach using Visual Studio Code and continuous deployment with Azure’s Github integration.

One potential first step to developing a simple Node project without any IDE is to use Express. If you have the Node Package Manager (npm) installed, you can install Express. Express is one of the more popular frameworks for building Node applications. Creating and scaffolding a project with Express is as simple as typing this from the command line:

npm install -g express-generator
express myApp
cd myApp
npm install

With those four little lines of code, we can a runnable Node application. While you’re in the application’s working directory, we can run the application like so:

npm start

The default applications starts a web server and listens on port 3000. I typically changes this to 8080, though. If we browse to the localhost endpoint with our browser, we’ll see something like this:

At this point, we can take this default project and put it into a Github repository. Using a previously created Azure web site, it’s pretty straight forward to get continuous deployment from Git to your website. Using the Azure portal and browsing to the tools tab for the website, take a look at the continuous deployment settings. You’ll see the option to configure a source:

You’ll walk through the process of configuring your repository source and have to provide Azure with access to your Git account.

Once you check all of the boxes, it looks something like this:

You could stop there, but you’ll probably want to pull the web.config file that Azure creates for you into your Git repository for posterity sake. This will allow you to modify some important server settings like paths, minetypes, and such. I want bore you too much with how to access your website, but to access the website over FTP, you have to first setup deployment credentials. These settings are accessible via the website properties:

Once the credentials are set, you can see what the FTP address is in the properties section:

With the credentials you configured and the FTP URL, you can use your favorite FTP client to access the site/wwwroot folder to download the web.config and put it into your Git repository. I like to use Filezilla. Here’s what the typical configuration in Filezilla looks like:


Finally, with all of this in place, your application should automatically start deploying to your Azure website. However, I did run into a few issues with the default Express scaffolded application throwing 500 errors. Rather than going around and around to figure out the issue, I highly simplified the app.js that Express builds by default and changed the package.json to run the app.js rather then “bin\www.” For me, this greatly simplified the Node applicaiton. Also, for my purposes, I mainly wanted to create this simple Node application for creating/testing API end-points for demos.

Since my primary use case is demo API endpoints, I took the sample code from my previous blog post and put it into its own route. This route is added to the list of routes available in app.js. It’s pretty simple to just add more routes as I need/want more data providers to test against. With everything in place, I can browser to the Node application’s routes like so:

https://long2know.azurewebsites.net/api/customer/1
https://long2know.azurewebsites.net/api/customers

The source code for my Node project is on Github.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.