1

I have an Angular app (9.1.4) and a node.js server application (12.14.1). My files are currently configured like this:

MyApp
- package.json
- angular.json
- server
  - server.js
- src
  - app
  - asserts
  - environments
  - angular html/css/ts
- node_modules

In order to runt his locally I have to run node server.js in one cmd prompt and ng serve in another. I hope to deploy this project to Azure but am not sure how to set this up so that it can run in a single app service. So:

  1. How do I run the server (node.js) and the app (angular) via the same command locally?
  2. Once I have this setup locally, what (if anything) needs to be changed in order to run in Azure?

1 Answers1

0

First of all, are the startup ports of your project, front-end angular project and back-end node service in the same configuration file?

  1. If yes, then you can execute multiple commands by modifying the script in the package.json file.

  2. Because only 443 and 80 ports are supported in azure web app. If the port configuration of the two projects is not the same, it may run normally locally.

For example, the ng project is 7001, and the server project is 7002, deployed to the azure web app, according to the process.env.PORT parameters, it will the port conflicts and the project cannot be started.

So if it is the second case, how to deal with:

You can use virtual applications to deploy your applications separately. For more details, you can see my answer in another post.

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • This is helpful! I am now running multiple commands locally and launching the server and the app at the same time. But how do I do this in my azure web app? How do I set this startup command? I used FTP to deploy the angular app, but the server doesn't seem to be running as I can't hit any of the APIs. I think it may be related to the port? I just have it hardcoded right now to 3000, which is none of the ports you mentioned above. How do I configure this? –  Aug 13 '20 at 06:11
  • @alanafrankly You can add start command in portal with `npx serve -s`. – Jason Pan Aug 13 '20 at 06:18
  • @alanafrankly What I mean is, although your project is divided into front-end and back-end, you still need to use it in your coding, such as `app.set('port', process.env.PORT || 3000); `, the backend is set to `app.set('port', process.env.PORT || 3001);`, while `443` and `80`, they are running in azure, `process.env.PORT` The default value. – Jason Pan Aug 13 '20 at 06:25
  • @alanafrankly You cannot hard-code the configuration port value. Just set it like `app.set('port', process.env.PORT || 3000)` . – Jason Pan Aug 13 '20 at 06:27
  • @alanafrankly Have you used a virtual application? – Jason Pan Aug 13 '20 at 06:28