reactjs – How to Configure Port Binding for Express Backend and React Frontend on Render

I’m deploying a Node.js and React app on Render, but I’m facing issues with port binding. My React app runs on port 3001 locally, and my Express backend runs on port 3000, but when I deploy it on Render, I’m unsure how to configure the ports properly for both services. Building on render.com

Backend (Express):

I’m using MongoDB for database connections and the app is set up with Express.
I have the backend listening on port 3000 locally, but Render requires my backend to use the port provided by the PORT environment variable.
Help

const PORT = process.env.PORT || 3001;
app.listen(PORT, '0.0.0.0', () => {
  console.log(`Server running on port ${PORT}`);
});

Read more here: Source link