Deploying a Typescript-enabled Express application on the Azure cloud platform

Currently, I am attempting to deploy an Express server on Typescript on Azure by following the guidelines provided in this tutorial: https://learn.microsoft.com/en-us/azure/app-service/quickstart-nodejs?tabs=windows&pivots=development-environment-vscode

The application is a simple dummy app with a basic "Hello World" in an index.ts file. However, I am encountering several issues during the deployment process.

Upon trying to access the website, the message I receive is: "You do not have permission to view this directory or page."

Upon inspecting the deployed folder, I noticed that there is no web.config file present. Despite setting the "SCM_DO_BUILD_DURING_DEPLOYMENT" parameter to true, it fails to generate the file.

Below is an excerpt from my package.json file:

{
  "name": "test-azure-3",
  "version": "1.0.0",
  "description": "",
  "main": "dist/index.js",
  "scripts": {
    "prebuild": "tslint -c tslint.json -p tsconfig.json --fix",
    "build": "tsc",
    "prestart": "npm run build",
    "start": "node .",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.2"
  },
  "devDependencies": {
    "@types/express": "^4.17.13",
    "@types/node": "^17.0.14",
    "tslint": "^6.1.3",
    "typescript": "^4.5.5"
  }
}

Here are my settings in Azure:

https://i.sstatic.net/rdGIW.png

https://i.sstatic.net/m5PxI.png

(I find it a bit unexpected to see .Net as the stack)

If you require any additional information, please feel free to ask!

EDIT: Following Felipe's suggestion, I went ahead and created a separate Azure project for the dist folder, but unfortunately, the issue persists.

https://i.sstatic.net/VwQqF.png

Answer №2

When utilizing Azure app service, it has the capability to retrieve a zip file if one is present. In order to achieve this, you need to compress your dist folder in the pipeline and utilize that repository as the source for the app service. If you are working with Azure repos, the process is quite simple. Include the following code in your pipeline configuration file:

 - script: |
     npm run build
   displayName: 'npm build'
   
 - task: ArchiveFiles@2
   inputs:
     rootFolderOrFile: 'dist'
     includeRootFolder: true
     archiveType: 'zip'
     archiveFile: 'dist.zip'
     replaceExistingArchive: true

Your start script in package.json file should be configured as follows:

"start":"node dist/index.js"

Furthermore, Azure app service relies on docker containers which expose port 8080. Thus, your application must be operational on port 8080.

Answer №3

After reviewing everything we covered:

  1. Keep in mind that web config is specific to IIS, NodeJS is not impacted by it;
  2. Make sure to execute "npm run build" and publish only the files in the "dist" folder. This will create an index.js file in the main directory, which Node will use to run your application. Avoid running .ts files in a production environment;
  3. Include the necessary environment variables in the "Application Settings" on Azure. This will provide your app with the required variables for operation;
  4. Consider setting the PORT variable to 80 as Azure may expect your app to run on port 80;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The function successfully triggers when clicked using (React, JS, TS) but does not respond to key presses

When the function is called with "onClick", it works correctly, but when called with "onKeyPress", it does not execute an if statement. scenario Consider a scenario where you can search for food recipes (e.g. "pizza") and receive a list of recipes from a ...

Angular button press

Recently, I started learning Angular and came across a challenge that I need help with. Here is the scenario: <button *ngIf="entryControlEnabled && !gateOpen" class="bottomButton red" (click)="openGate()">Open</button> <button *ngIf ...

The aesthetic of the material tree design is not being reflected as expected

I am attempting to recreate the material tree example showcased here. This is the desired outcome: https://i.sstatic.net/dnkm2.png However, my result appears like this: https://i.sstatic.net/JXdbo.png Below is the HTML code I am utilizing: <mat-tr ...

The attribute 'attribs' is not found on the 'Element' type in cheerio

When I run my code, I encounter an error that says Property 'attribs' does not exist on type 'Element'. It's puzzling to me why this error is being thrown. After examining the type definitions of cheerio, I discovered that attribs ...

What is the method for defining the type of a variable without assigning a value to it?

Working on an Angular 11 project using Typescript with Strict Mode, I encountered the following issue: export class AvatarComponent { @Input() user: UserModel = null; } This resulted in a compilation error: Type 'null' is not assignable to ty ...

Error: User validation failed because the password field is empty. Please make sure to provide a password

Registering users and authenticating them using passport-local-mongoose is giving me some trouble. When attempting to register a user, I encountered the error 'User validation failed: password: Path password is required.' To workaround this issue ...

What is the process for transferring items in carts to a new session after logging in?

My tech stack includes passportjs, express-session, and React. I am currently storing cart items in the session and utilizing express-mysql-session to store new carts in both the session and the MySQL database simultaneously. However... When a user logs ...

We encountered an issue: `TypeError: expressJwt function is undefined`

As I work on developing middleware for user authorization within my application, I encounter an issue while attempting to determine if a route necessitates signing in. The relevant snippet of code is presented below: const { expressJwt } = require ...

Some specific pages in my Express/EJS application seem to hang indefinitely on "Waiting for localhost..."

I'm currently developing a Node/Express/EJS application, and I've noticed that most pages displaying data passed through my EJS templates seem to get stuck at "Waiting for localhost..." var express = require("express"); var app = express(); var ...

Uploading Files within Angular FormArray

I am facing an issue with my formArray which contains file upload inputs in each element. Whenever I upload an image in one input, it changes the values of other file inputs in different rows. https://i.stack.imgur.com/3haZW.png Current Behavior: Uploadi ...

Issue with updating arrays in Mongoose not functioning as expected

Attempting to update values involves finding the object, pushing a value into 2 arrays, and then updating the original value. Although the object is found and values are successfully pushed, the update function fails to detect the changes, resulting in an ...

In Next.js, I am experiencing an issue where the Tailwind class is being added, but the corresponding

I'm currently in the process of developing a board game where I need to track players and their positions on specific squares. My goal is to display a small colored dot on the square where each player is positioned. Here's a snippet of my templa ...

Is there a way to keep a button in a "pressed" state after it has been clicked?

Could someone kindly share the code with me? I am looking for a button that remains pressed after clicking it. At times, I feel embarrassed for struggling with seemingly simple tasks. Grateful for any guidance or solution provided by this community! Man ...

Are the functions 'useEffect' and 'useCallback' being repetitively used in this case?

I have implemented a custom hook in my React application to manage back navigation actions (POP). The functionality is operational, but I can't help but notice that useCallback and useEffect seem to be performing similar tasks. Here is the snippet of ...

Error TS2307: Module 'bluebird' not located

Currently, my focus is on developing an app using Ionic 2 and Angular 2 along with Typescript. To incorporate messaging into my app, I opted to utilize the library amqp-ts. The installation of the library through npm was successful with the following comma ...

Trap mistakes while utilizing async/await

Within my Express application, I have a register function for creating new users. This function involves creating the user in Auth0, sending an email, and responding to the client. I am looking to handle errors from Auth0 or Postmark individually and send ...

Discover the seamless process of retrieving user details from Postman API with a single click of the submit button on the front-end using Express and Node.js

Trying to display user input directly in Postman by submitting the submit button. This is my code: import express from "express"; import {dirname} from 'path'; import {fileURLToPath} from "url"; import bodyParser from "b ...

Transfer data from Node.js to J2ee via binary upload and receive a corresponding reply

I am in need of assistance with my Node express server. The server receives a binary file (pdf) from a client and I must send this binary file as it is to a Java servlet. Currently, I am using the following code snippet to accomplish this task by utilizing ...

Tips for using conditional rendering with React and TypeScript

Issue with Conditional Rendering in TypeScript It seems like I might have encountered a problem with the way I declare my components. Take a look at this TypeScript snippet: import React, { FunctionComponent } from 'react'; export const Chapte ...

What is the best way to redirect nodejs requests to a separate nodejs application?

Hello! I am currently working on a project to create an API gateway using Node.js and Express. The goal is to showcase a small-scale microservices architecture by routing requests to different microservices. For instance, if I have microservices A, B, and ...