To deploy a Node.js and React app in Azure App Service, you can follow these general steps:
- Set Up Your Environment:
- Ensure you have an Azure account with an active subscription. If you don't have one, you can create an account for free.
- Install Node.js LTS and verify the installation by running
node --version. - Install Visual Studio Code and the Azure App Service extension for Visual Studio Code.
- Install the Azure CLI to run commands for creating and configuring Azure resources.
- Prepare Your Application:
- Ensure that your Node.js backend is set up to listen on the port provided by the
PORTenvironment variable. This is typically done in your Express app's startup script. - Build your React app using
npm run buildto create a production-ready version of your application.
- Ensure that your Node.js backend is set up to listen on the port provided by the
- Deploy to Azure:
- Open Visual Studio Code and ensure you are in the directory of your Node.js application.
- Use the Azure App Service extension to create a new Web App. You can choose between Linux or Windows as your operating system, and select the Node.js version you want to use (Node 24 LTS is recommended).
- For the pricing tier, select Free (F1) to avoid any costs.
- After creating the Web App, deploy your application code. You can do this by right-clicking on your App Service and selecting the option to deploy.
- If using the Azure CLI, you can deploy your app using the command
az webapp up --sku F1 --name <app-name>.
- Configure Application Settings:
- After deployment, you may need to configure application settings in Azure, such as enabling build automation if necessary.
- Ensure that all required npm dependencies are included in your deployment, as Azure will automatically run
npm install --productionduring the deployment process if you deploy via Git or Zip package.
- Test Your Application:
- Once deployment is complete, you can browse to the URL of your Azure Web App to see your application running.
By following these steps, you should be able to successfully deploy your Node.js and React application to Azure App Service.
References: