React and Vite
How to host a React app: build it, upload it, fix the routes
A React app is a folder of static files once it is built. Here is how to put that folder online, on free hosts or on cPanel shared hosting, without the blank-page and 404 surprises.
To host a React app, run npm run build and upload the contents of the dist/ folder (Vite) or build/ folder (Create React App) to any static host. Add a fallback that serves index.html for unknown routes so page refreshes work. Free hosts suit hobby projects; cPanel hosting from ₹900 a year adds your own domain and email.
A React app runs in the visitor's browser. The server only has to hand over some HTML, JavaScript and CSS files, which means almost any web host can serve it, including cheap shared hosting. The work is on your side: building the app correctly, uploading the right folder, and telling the server what to do with routes it does not recognise.
Key takeaways
- Upload the build output, never the project folder. For Vite that is
dist/; for Create React App it isbuild/. - Single-page apps need a fallback to
index.html, or refreshing/aboutshows a 404. - Everything in a front-end
.envfile ends up public. Real secrets belong on a server. - If your app has its own Node.js API, that API needs a server that keeps Node running, which we do not host.
Step 1: Build the app
Run the build command in your project folder; it produces a small folder of static files that is the only thing you upload.
npm install
npm run build
npm run preview
npm run preview serves the built Vite app locally, so you can check it before uploading. Create React App has been deprecated by the React team, so new projects mostly use Vite; if yours is an older CRA project, its output goes to build/ instead. Never upload node_modules, src or your .env file.
Step 2: Get the base path right
The base path tells Vite where your app will live, and getting it wrong is the usual cause of a blank white page. By default Vite writes asset links such as /assets/index-abc123.js, which work only at the root of a domain.
// vite.config.js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
base: './',
})
- At the domain root (
yourname.in): the defaultbase: '/'is fine, and it is the safer choice if you use deep routes such as/projects/42. - In a subfolder (
yourname.in/app/): setbase: '/app/'and give React Router the samebasename. - Unknown location, such as a preview link:
base: './'makes links relative so the same build works anywhere. It can break assets on deep routes, so switch back to an absolute base for the final site if you see that.
Step 3: Choose where to host it
For a hobby project a free static host is genuinely enough; choose paid hosting when you want your own domain, email and a fixed yearly bill in one place. At the time of writing:
| Host | Good for | Watch for |
|---|---|---|
| Our free upload tool | A preview link for dist/ in seconds, no account | 4 hours, or 24 hours with a confirmed email; login forms blocked |
| Netlify | Deploying from Git, with a free plan | The free plan has monthly usage credits; add a _redirects file for routes |
| Vercel | Vite and Next.js projects deployed from Git | The free Hobby plan is for personal, non-commercial use |
| GitHub Pages | Free hosting from a public repository | No server rewrites, so deep links need a workaround or HashRouter |
| cPanel hosting | Your own domain, email and SSL on one yearly plan | Needs the .htaccess fallback below |
To test before choosing, drop your dist/ folder on our upload tool. It already falls back to index.html for app routes, so React Router works on the preview without any setup.
Step 4: Upload to cPanel or other shared hosting
On cPanel, upload the contents of dist/ into public_html, so that index.html sits at the top level with the assets folder beside it. Zip the contents, upload the ZIP in File Manager and extract it. Hostinger-style panels such as hPanel work the same way through their own file manager.
Then add the routing fallback. Apache, which runs most cPanel servers, reads an .htaccess file next to index.html:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Real files, such as images and scripts, are served as normal; any other path gets index.html, and React Router takes over. For a subfolder, change both / paths to /app/. Put the file in Vite's public/ folder and it is copied into every build automatically. Our cPanel plans include free SSL and email on your domain.
Environment variables are public
Anything your React code can read, every visitor can read. Vite puts variables starting with VITE_ into the JavaScript bundle at build time, and Create React App does the same with REACT_APP_. Changing them means rebuilding.
Public keys designed for browsers, such as a Supabase anon key or a payment gateway's key ID, are fine. Secret API keys, database passwords and SMTP passwords are not. Our guide to hosting Lovable, Bolt and v0 projects lists which keys are safe to ship.
When your app needs a server
If your React app talks to your own Express or other Node.js API, that API needs hosting that keeps a Node process running, which cPanel shared hosting does not provide. We do not offer VPS or app hosting, so the API needs a specialised provider, such as a cloud VPS provider or a managed Node platform like Render, Railway or Vercel functions. The static front end can still sit on our cPanel plans or the upload tool and call the API by its URL.
The same applies to Next.js features such as server-side rendering and API routes: anything that needs a running Node server is not something we host. A Next.js site using static export produces an out/ folder that works like any other static build, on our cPanel plans with the same .htaccess fallback.