How to Host a React Front-End with a Node.js Backend on cPanel
The clean way to host a React front-end with a Node.js backend on cPanel is to serve the built React files as static content and run the Node API separately through Setup Node.js App. Keeping them separate is simpler and performs better than trying to serve everything from Node.
The recommended setup
- React front-end — build it to static files and serve them from your domain (fast, cached, no Node process needed).
- Node.js API — run it as an app, ideally on a subdomain like
api.yourdomain.com.
Step 1: Build and upload React
Run your production build locally, then upload the built files to your domain's document root via File Manager. They are served as static content.
Step 2: Deploy the Node API
Create the backend in Setup Node.js App on its own subdomain, set the root and startup file, install dependencies, and ensure it listens on process.env.PORT. See deploying an Express app.
Step 3: Connect them
Point your React app's API calls at the backend's URL (for example https://api.yourdomain.com). Because the front-end and API are on different subdomains, configure CORS on the Node side to allow requests from your front-end's origin.
Step 4: Secure both
Add SSL to both the front-end domain and the API subdomain so everything runs over HTTPS.
Frequently asked questions
Why not serve React from the Node app?
You can, but serving the React build as static files is faster and lighter — static content is cached and needs no Node process. Reserve Node for the API.
My front-end can't reach the API (CORS error).
Configure CORS on your Node backend to allow your front-end's origin. Cross-subdomain requests are blocked by default until you explicitly permit them.
Should the API be on a subdomain?
It is the cleanest approach — api.yourdomain.com keeps the backend separate from the front-end and simplifies routing and SSL.
Was this article helpful?