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.

In short

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 is build/.
  • Single-page apps need a fallback to index.html, or refreshing /about shows a 404.
  • Everything in a front-end .env file 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 default base: '/' is fine, and it is the safer choice if you use deep routes such as /projects/42.
  • In a subfolder (yourname.in/app/): set base: '/app/' and give React Router the same basename.
  • 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:

HostGood forWatch for
Our free upload toolA preview link for dist/ in seconds, no account4 hours, or 24 hours with a confirmed email; login forms blocked
NetlifyDeploying from Git, with a free planThe free plan has monthly usage credits; add a _redirects file for routes
VercelVite and Next.js projects deployed from GitThe free Hobby plan is for personal, non-commercial use
GitHub PagesFree hosting from a public repositoryNo server rewrites, so deep links need a workaround or HashRouter
cPanel hostingYour own domain, email and SSL on one yearly planNeeds 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.

Frequently asked questions

Can I host a React app for free?

Yes. At the time of writing, Netlify, Vercel and GitHub Pages all have free options for static React builds, each with its own limits; Vercel's free plan is for non-commercial use. Our upload tool gives a free preview link for 4 hours, or 24 hours with a confirmed email. Paid hosting adds your own domain, email and a predictable bill.

Why do I get a 404 when I refresh a page in my React app?

The server is looking for a real file called, for example, /about, and there is none. Add a fallback that serves index.html for unknown paths: an .htaccess rewrite on Apache and cPanel, or a _redirects file on Netlify. React Router then shows the right page.

Why is my React app a blank white page after uploading?

Usually the asset paths are wrong or the wrong folder was uploaded. Open the browser console: 404 errors for files in /assets mean the base path does not match where the app lives. Check that index.html sits directly in public_html, not inside a dist folder.

Can I host a React app on cPanel shared hosting?

Yes. A built React app is static files, which cPanel serves well. Upload the contents of dist or build to public_html and add the .htaccess fallback for routes. Only a Node.js back end or server-side rendering needs more than shared hosting, and that part needs a Node host elsewhere.

Are variables in my .env file safe in a React app?

No. Variables your front-end code reads, such as VITE_ or REACT_APP_ variables, are copied into the JavaScript files that every visitor downloads. Keep secret keys on a server and have your app call that server instead. Rotate any secret that was ever in a public build.

Where do I host the Express API behind my React app?

On a host that keeps a Node.js process running, such as a cloud server or a managed Node platform like Render or Railway. We do not offer VPS or app hosting, so this part needs a specialised provider. The React front end can stay on our cPanel plans or another static host and call the API by its URL.

WhatsApp