How to run both Node.js and Python flask on Azure web app

Rony Tayoun 20 Reputation points
2025-01-16T08:54:22.3733333+00:00

Basic Azure webapp question. I have run both tutorials:

Quick start Node.js on webapp and Quick start deploy flask on webapp
Now adding the 2 of them together is giving me a nightmare. To add backend functionality on the Node.js by providing flask is not working.
If I put the runstack python, the node.js won't work, and if I put the runstack as Node, the python flask wont execute (or not running on the right port)

Locally it works like a charm.

What is the proper way to do it and on which port ?

Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,060 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bhargavi Naragani 235 Reputation points Microsoft Vendor
    2025-01-27T08:16:56.0233333+00:00

    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:

    1. Set up both your Node.js and Flask apps in the same container.
    2. Use a process manager like forever or pm2 to keep both apps running at the same time.
    3. 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"]
    
    1. Build the image on your local machine and test it.
    2. Push the image to a container registry (like Azure Container Registry).
    3. 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:

    1. Create one Azure Web App for your Node.js app.
    2. Create another Azure Web App for your Flask app.
    3. Use APIs: Your Node.js app can call the Flask APIs for any backend tasks.
    4. Store the endpoints for communication in environment variables.
    5. 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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.