Javascript and Node.js multi-environment deployments with Azure Pipelines

Fatih KÜÇÜK
KoçSistem
Published in
3 min readFeb 23, 2022

You can create many environments for your Node.js apps. Each environment may have its own specs and differences. This article will describe how you can deal with it. Configurations, as defined by the Twelve-factor app methodology, are everything that changes between deployments. API and log level are marvelous examples of this concept. By managing this configuration outside of the application, we’re more likely to be able to build the application build once and run it anywhere.

In this tutorial, I used the sample code block below.

The folder structure looks like below.

--root
----node_modules
----.env.json
----app.js
----package.json
----web.config

There are a lot of packages in npm for managing environment variables but in this section, I used dotenv-json-complex. This package solves complex environment variables via JSON file.

Let’s take a look at Azure Pipeline.

As you can see, there isn’t another build pipeline or another branch. You can manage your javascript app with a single Azure Pipeline.

How could it be possible?

In this section, you can see how magic works. You will see how it works by managing this configuration outside of the application.

I mentioned dotenv-json-complex library above and shared the sample JSON file. I used a nodeEnv key from the JSON file after that I can change it easily in Azure Pipeline.

Add a JSON file in the JSON variable substitution textbox.

Then specify the value and scope of the variable.

The images below demonstrate the magic of DevOps.

Production Environment

Development Environment

In this example, I used Azure App service, but you can design it in a different scenario with the File Transform task.

--

--

Fatih KÜÇÜK
KoçSistem

Fatih is a technology lover with interest in DevOps, Agile, Container and Container Orchestration.