The nest js build it’s not including the package.json which seems to be normal, but then when deploying to azure web app, the server it was not capable to install the needed packages. Finally I have uploaded manually the package.json file and installed manually the dependencies, but I am sure this is not the way to do it. What is the correct way to deploy a nest.js app?
I deployed my dist folder as generated from the build and I expected the azure web app to be able to start my app without further manual workarounds.
2
Answers
If you are planning to deploy from Azure DevOps follow these steps. Medium
I created Sample nestjs App and deployed to the Azure web app (Linux) through VS code.
Thanks @Azure OSS Developer Support for Clear Explanation.
dist
folder andpackage.json
are needed, So Entire Project needs to deploy.Below is My complete Project Structure.
This is because Azure Web App needs the
package.json
file to know which dependencies to install. Withoutpackage.json
, which leads to runtime errors.The Nest project created listens on port 3000 by default. But in Azure Web App dynamically assigns a port number to application at runtime. This port is provided via the
PORT
environment variable.So, I define the port in main.ts file as shown below.
Below is the complete code.
main.ts:
Make sure to add the start script to the package.json as shown below.
In VS code select Angular Extension -> Subscription -> Azure Web App -> Deploy to Web App -> Complete Project Folder as shown below.
It is Successfully deployed to Azure Web app.
Azure Web App Output: