Hi @Rony Tayoun,
Welcome to the Microsoft Q&A Platform!
It seems like you're having trouble running both Node.js application and Python flask application together within the same Azure Web App.
To run Node.js and Python flask together, you can either use Azure App Service with a custom container or deploy them as separate web apps and establish communication between them.
Option 1:
Build a custom Docker container that allows both your Node.js and Flask apps to run side by side. Here’s how to do it:
- Set up both your Node.js and Flask apps in the same container.
- Use a process manager like
forever
orpm2
to keep both apps running at the same time. - Make sure they use different ports (like Flask on port 5000 and Node.js on port 3000).
Example snippet for a Dockerfile:
FROM ubuntu:20.04
# Install Node.js
RUN apt-get update && apt-get install -y nodejs npm
# Install Python
RUN apt-get install -y python3 python3-pip
# Copy Node.js app
COPY ./nodejs-app /nodejs-app
WORKDIR /nodejs-app
RUN npm install
# Copy Flask app
COPY ./flask-app /flask-app
WORKDIR /flask-app
RUN pip3 install -r requirements.txt
# Use a process manager to run both
CMD ["sh", "-c", "npm start --prefix /nodejs-app & python3 /flask-app/app.py"]
- Build the image on your local machine and test it.
- Push the image to a container registry (like Azure Container Registry).
- Deploy the image to an Azure Web App set up for container deployment.
Azure Web App:
Deploying Docker Containers on Azure App Service
Option 2:
If you prefer to keep the apps separate, this might be the simplest way to manage them:
- Create one Azure Web App for your Node.js app.
- Create another Azure Web App for your Flask app.
- Use APIs: Your Node.js app can call the Flask APIs for any backend tasks.
- Store the endpoints for communication in environment variables.
- Azure Web Apps automatically handle port conflicts, so you won’t need to worry about assigning ports manually in this setup.
If the answer is helpful, please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.