Just to highlight, the Node.js apps must be deployed with all the required NPM dependencies. The App Service deployment engine automatically runs npm install --production
for you when you deploy a Git repository, or a Zip package with build automation enabled.
When you say starting the app using pm2 serve, I believe you have added the “Start file" (start command) section on app settings on Azure Portal.
For a custom start file use either of the supported extensions: .js file / PM2 file with the extension .json, .config.js, .yaml, or .yml
For Nestjs on Linux WebApp, try these flow:
- Navigate to the src/main.ts and change the port from 3000 to process.env.PORT
- Navigtate to the .gitignore and remove the dist from the compiled output section
- In the command line run "npm run build" this will trigger npm to run the build script in the package.json and produce a dist folder.
- Deploying the application via git/github should trigger the oryx build which will install the node modules needed to run the app
- In the portal, navigate to configuration and set the startup command to "node dist/main.js"
Then, check to see of the WebApp works fine.
In case, your using App Service on Windows, add a web.config file to the root of the application (Nestjs Web.config)
Kindly see this doc for more info Configure a Node.js app for Azure App Service