I am developing a Node.JS project package.json and app.js (app.js is the main file of the project). I am using postgresql, I've placed all db related configuration under environmental variables.
I am trying to deploy the below project in Azure DevOps using CI/CD pipeline. This is a web app using Azure Repos.
Current Implementation:
Without CI/CD pipeline, following the below method to deploy the code and it's working fine.
Currently under Deployment Center Selected following items:
- Source: Azure Repos
- Azure Repos:
- Project: Project Name
- Repo: Repo name
- Branch: branch
- Build: Azure pipelines
Error I am getting after deployment:
In the logs I can see the deployment success, but when I hit the URL of the Node.js app, I see This Page isn't working right now or Internal server 500.
Steps I have followed:
Step 1: I am using Azure Repo Please Note: I am using Classic Editor
Step 2: Clicking pipelines (blade) --> pipelines --> New pipeline
Step 2.1: Clicking pipeline (Build Pipeline) Entering the following fields:
- Name: Node-JS BackEnd Project
- Agent Pool: Azure pipelines
- Agent Specification: Windows Latest
Step 2.2: Get
sourceMapsEnabled(My-Repo and Branch)Step 2.3: Selecting AgentJob (npm Editing Following Fields):
- Task Version: 1
- Display Name:
npm install - Command: install
- Working folder that contains
package.json:./
NOTE: LEFT OTHER OPTIONS AS IT IS in Step 2.3
Step 2.4: Selected Copy Files to (Edited Following Details):
- Task Version: 2
- Display Name: Copy Files to:
./ - Source Folder:
./ - Contents:
***.js,***.json, - Target Folder:
./
NOTE: LEFT OTHER OPTIONS AS IT IS in Step 2.4
Step 2.5: Selected Archive Files LEFT ALL OPTIONS AS IT IS: 1.Archive Type: zip
Step 2.6: Publish artifacts: drop LEFT ALL OPTIONS AS IT IS
After the above steps, I ran the build, which was successful, and I can see the updated code in artifacts.
Step 3: In Pipelines Blade Clicked (Releases) Create Release.
Step 3.1: Added by Artifact
Step 3.2: Clicked Run On Agent and added (Azure App Service deploy)
Step 3.3: Edited Following fields in Azure App Service deploy:
- Task Version: 4
- Display Name: App service deploy
- Connection Type:
Azure Resource Manager - Azure Subscription: xxxxxx
- App Service Type: Web app on Windows
- App Service name: node-js-backend-project
- Package or folder:
$(System.DefaultWorkingDirectory)/**/*.zip
NOTE: OTHER OPTIONS IN Step 3.3 LEFT AS IT IS
After the above steps, I clicked create release - I can see all the jobs success. When I am hitting the backend URL I am getting the same issue (Internal server 500 error).
Code:
//Package.json:
{
"name":"Node-backend-project",
"version":"1.0.0",
"main":"app.js"
"scripts":{
"start" : "nodemon app.js",
"dev": "node app.js"
}
"dependencies":{
"@azure/storage-blob":"^12.0.0",
"axios":"^1.6.2",
"cors":"^2.8.5",
"dotenv":"^16.3.1",
"express":"^4.18.1",
"express-fileupload":"^1.4.3",
"lowdb":"^1.0.0",
"passport":"^0.6.0",
}
}
//app.js
const express = require("express");
const cors = require("cors");
const rateLimit = require("express-rate-limit");
const router = require("./routes/index");
const pool = require("./db");
require("dotenv").config();
const upload = require("express-fileupload");
const { pipeline } = require("stream")
const app = express();
const port = process.env.PORT || 5000;
const limiter = rateLimit({
WindowMs:12*60*1000,
max:70,
standardHeaders:true,
legacyHeaders:false,
})
app.use();
app.use(cors());
app.options('*', cors());
app.use(express.json());
app.use(express.urlencoded({extend:false}));
app.use(router);
app.use(upload());
async function testConnection() {
try {
const client = await pool.conect();
client.release();
}catch(err){
console.error("Error", err)
}
app.listen(port, async () => {
await testConnection();
})
}
I have tried many solutions from StackOverflow and Microsoft documentation (where they use only Hello World program to deploy) but no solutions are working for me. Instead of Azure App Service, I tried with Azure Web App deploy also, but I am getting the same result. I have copied and pasted the web.config file (renamed the index.js to app.js) from the below StackOverflow link:
Azure Node.js Internal Server Error from index.js file
I am not clear on what I am doing wrong. From the front-end when I am hitting the dev URL I can see that I am getting internal server error (500 error).
Could anyone guide me to successfully host the Node.js app in Azure DevOps using CI/CD pipeline? Thanks in Advance!





