Skip to main content
All articles

Deploying a Node.js + React App on Hostinger: 5 Lessons Learned

By Yasin ArafatSep 26, 20264 min read

This portfolio — a React front end with an Express and MySQL back end — runs on Hostinger's Node.js web app hosting. The first deploy was easy. Keeping it healthy through many redeploys taught me a few things that are not obvious from the dashboard. These are the five that mattered most.

1. Know exactly what the platform runs

In the deployment settings you choose a framework preset, a Node.js version, a package manager and an entry file. This app uses the Express preset with dist-server/server.js as the entry file and no build command, so on every deploy the platform:

  1. extracts the uploaded archive,
  2. runs npm install,
  3. starts the entry file.

That means the compiled front end (dist/) and the compiled server (dist-server/) must already be inside the archive. My release routine is simply:

npm run build   # vite build for the React app + tsc for the server
# then zip the project WITHOUT node_modules and upload it

2. Do not upload node_modules

My early archives included node_modules and weighed more than 50 MB. The platform runs npm install anyway, so I now leave it out — the archive dropped to about 7 MB and uploads in seconds.

One catch: if a production install skips dev dependencies, the server must not import them. My server imported Vite at the top of the file, even though Vite is only needed in development. Loading it lazily fixed that:

if (process.env.NODE_ENV !== 'production') {
  // Vite is a devDependency, so it is only loaded in development
  const { createServer } = await import('vite');
  const vite = await createServer({ server: { middlewareMode: true }, appType: 'spa' });
  app.use(vite.middlewares);
}

3. Every deploy is a fresh folder — keep uploads outside it

Images uploaded through my admin panel kept disappearing after deployments. The file manager explained why: each deployment is extracted into a new release folder and the previous release is removed. Anything the app writes inside its own folder is gone after the next deploy.

The fix is to store uploads in a folder next to the releases instead of inside them, and to make the location configurable:

// UPLOAD_DIR wins if set; in production use a folder outside the release,
// locally keep using the project's own uploads folder
const uploadDir =
  process.env.UPLOAD_DIR ||
  (isProduction ? path.join(siteRoot, 'uploads') : path.join(projectRoot, 'uploads'));

fs.mkdirSync(uploadDir, { recursive: true });
app.use('/uploads', express.static(uploadDir));

The public URLs stay the same (/uploads/…); only the folder on disk changes, so image links already saved in the database keep working.

4. Static files may never reach your app

Files in a Node app's public/ folder can be served straight by the web server, before Express ever sees the request. That is fast, but it also means an updated file is not always the one visitors get: after one deployment my updated robots.txt simply did not change on the live site.

Two quick checks show who answered a request:

# X-Powered-By: Express in the headers means your app served it
curl -sI https://example.com/robots.txt

# Ask the origin server directly, bypassing the CDN
curl -sI --resolve example.com:443:<origin-ip> https://example.com/robots.txt

If a static file refuses to update, compare the CDN and origin responses and find out which folder the web server serves it from. For images used by React components I now import them in code instead of placing them in public/. Vite then gives them a hashed /assets/… URL that changes whenever the file changes — no stale copies anywhere.

5. Verify every deploy in two minutes

A green Completed badge only means the files were deployed, not that the app works. My post-deploy checklist:

  • Open /api/health and confirm the database is connected.
  • Load the home page and one page that reads from the database.
  • Hard-refresh to make sure the new JavaScript bundle is served.
  • Read the last lines of the runtime log for startup errors.
curl -s https://example.com/api/health
# {"status":"ok","dbConnected":true}

Summary

  • Build locally, ship dist and dist-server, and let the platform install dependencies.
  • Keep dev-only packages out of the production import path.
  • Store uploads outside the release folder.
  • When a static file will not update, find out whether the web server or your app served it.
  • Check health, pages and logs after every deploy.
Share this article