How I run your apps locally, and how to host React & Next.js on Namecheap Shared Hosting
When we work together in this IDE, I have access to an embedded terminal in your workspace. To run your app locally, I simply execute:
npm run dev
This starts a local Node.js Development Server (usually Vite or Webpack). This server handles "Hot Module Replacement" (HMR), meaning it watches your files and instantly updates the browser when we change code. However, this server is only for development. It is not optimized or secure enough to be exposed to the internet.
Shared hosting (like Namecheap, Hostinger, GoDaddy) typically uses Apache or Nginx servers designed to serve static files (HTML, CSS, JS, Images). They do not natively run Node.js commands like npm start in their standard web directories.
Instead of running a dev server, we must "build" the project. This bundles all your React code into standard, minified static files that any web browser can understand.
npm run build
This command creates a dist folder (or build if using Create React App).
yourdomain.com/admin, the Namecheap server looks for a folder named "admin". It won't find it and will return a 404 Error.
To fix this, we tell the Apache server: "If a file or folder doesn't exist, just load index.html and let React handle the routing." We do this by creating a file named .htaccess in the public/ folder before building (so it gets copied to dist):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
dist folder (not the folder itself).public_html)..htaccess file is there!Next.js is traditionally a full-stack framework that requires a Node.js server. However, if you are purely building a frontend or using Supabase for your backend, you can export Next.js as a Static Site (SSG) to run on shared hosting without a Node server.
You must tell Next.js to do a static export instead of building for a Node server.
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export', // This is the magic line
trailingSlash: true, // Helps with static routing
images: {
unoptimized: true // Required because Next's image optimizer needs a Node server
}
};
export default nextConfig;
Run the standard build command. Because of the config change, Next.js will generate a static version of your site.
npm run build
This creates an out folder (instead of the usual .next folder).
Because you enabled trailingSlash: true, Next.js generates physical HTML files for every route (e.g., out/admin/index.html). Because physical files exist, Apache knows exactly how to serve them. An .htaccess file is generally not required for basic Next.js static exports, but adding a fallback error page is good practice.
out folder.public_html./api/*) or Server Actions when using output: 'export' on shared hosting. You must use an external database like Supabase directly from the client.