🟒 Node.js 101

A beginner-friendly guide to understanding Node.js and troubleshooting it on Hostinger

Business & Cloud Hosting Plans

πŸ€” What is Node.js?

πŸ• Think of it like a pizza kitchen.

Imagine a pizza restaurant. When customers place orders, the kitchen doesn't wait for one pizza to fully bake before starting the next one. It handles multiple orders at the same time β€” putting one in the oven, chopping toppings for another, and boxing a finished one all at once.

Node.js works the same way. It's a tool that lets your computer run JavaScript code and handle many tasks at the same time β€” without waiting for one to finish before starting the next.

Normally, JavaScript only runs inside a web browser (like Chrome or Firefox). Node.js lets JavaScript run on a server β€” the computer that stores and delivers your website to visitors.

So instead of just making buttons click and forms work on a webpage, with Node.js you can:
  • Build the backend of a website (the part users don't see)
  • Connect to databases to store and retrieve data
  • Handle thousands of visitors at the same time
  • Build APIs (ways for apps to talk to each other)
  • Create real-time features like live chat or notifications

The problem is node.js normally works with root access. Since Business and Cloud hosting doesn't have root access, hpanel deployment do all the actions that requiring root. It reads from the app details and package.json. Then, we install it for client! No npm command needed.

πŸ“¦ What is npm?

npm stands for Node Package Manager. Think of it as an app store for Node.js code. Developers use it to install ready-made tools (called "packages" or "dependencies") so they don't have to build everything from scratch.

Example: Instead of writing your own code to connect to a database, you install a package that already does it.

On Hostinger Business/Cloud plans, you cannot run npm commands manually via SSH. Instead, use the Redeploy button in hPanel β€” it automatically reinstalls all packages for you.

🧩 Popular Frameworks Built on Node.js

Developers often use frameworks (pre-built structures) on top of Node.js. Hostinger supports:

FrameworkWhat It's Good For
Next.jsFull websites with both frontend and backend (very popular!)
ReactInteractive user interfaces
Vue.jsFlexible, easy-to-learn frontend framework
AngularLarge-scale single-page applications
ViteSuper-fast build tool for modern web apps
Express.jsLightweight backend/API server

βš™οΈ How Does a Node.js App Work?

When someone visits your Node.js website, here's what happens behind the scenes:

πŸ‘€ Visitor
opens site
β†’
🌐 Browser
sends request
β†’
πŸ–₯️ Node.js
server receives it
β†’
πŸ—„οΈ Fetches data
(if needed)
β†’
πŸ“€ Sends back
the response

πŸ—οΈ The Build Process (What Happens When You Deploy)

When you upload your Node.js project to Hostinger, the platform does this automatically:

  1. Reads your package.json β€” the file that lists your app's settings and dependencies
  2. Installs dependencies β€” downloads all the packages your app needs (like npm install)
  3. Runs the build command β€” compiles/prepares your app (e.g., npm run build)
  4. Starts the app β€” launches it on port 3000 so visitors can access it
Your app must listen on port 3000 on Hostinger Business/Cloud plans. This is a fixed requirement.

πŸ“„ The package.json File β€” What Is It?

πŸ›’ Think of it like a shopping list for your app

When Hostinger deploys your Node.js app, it doesn't know what tools and libraries your app needs to run. The package.json file is that shopping list β€” it tells Hostinger exactly what to install.

When you click Deploy or Redeploy in hPanel, Hostinger reads this file and automatically installs Node.js and every package listed under "dependencies". You don't need to do anything manually β€” it all happens behind the scenes.

Here's what a typical package.json looks like and what each part means:

// package.json β€” your app's ID card & shopping list
{
  "name": "my-website",          // the name of your project
  "version": "1.0.0",         // the version of your project
  "engines": {
    "node": "20.x"            // which Node.js version to use
  },
  "scripts": {
    "build": "next build",    // command to build the app
    "start": "next start"     // command to start the app
  },
  "dependencies": {
    "next": "14.0.0"          // βœ… installed on server β€” needed to RUN the app
  },
  "devDependencies": {
    "eslint": "8.0.0"         // ❌ NOT installed on server β€” only for development
  }
}
dependencies vs devDependencies β€” what's the difference?

β€’ dependencies = packages your app needs to actually run (like the engine of a car). Hostinger installs these automatically during deployment.
β€’ devDependencies = packages only needed while a developer is writing code (like a mechanic's tools). These are not installed on the server.

If a package your live app needs is placed in devDependencies by mistake, Hostinger won't install it β€” and your app will crash.
Runtime packages must be in "dependencies", NOT "devDependencies". This is one of the most common causes of deployment failures.

πŸ“š Key Concepts You Should Know

🌿 Environment Variables (.env)

These are secret settings your app needs β€” like database passwords or API keys. They're stored separately from your code so they're not exposed publicly.

DB_HOST=localhost
DB_PASSWORD=mypassword
PORT=3000
NODE_ENV=production

On Hostinger, you set these in hPanel β†’ Website Dashboard β†’ Environment Variables.

πŸ”’ Node.js Versions

Just like apps have versions, so does Node.js. Hostinger supports:

  • 18.x (older, stable)
  • 20.x (recommended)
  • 22.x (newer)
  • 24.x (latest)

Your project's package.json should specify which version it needs. Mismatches cause build failures.

πŸš€ Deployment Methods

GitHub Integration β€” Connect your GitHub repo. Every time you push code, Hostinger automatically rebuilds and redeploys. Best for active projects.

ZIP Upload β€” Upload a compressed file of your project. Simpler, good for static projects. Don't include the node_modules folder in the ZIP!

πŸ“Š Logs (Your Best Friend)

When something goes wrong, logs tell you exactly what happened. There are two types β€” and knowing which one to check first saves a lot of time:

  • Build Logs β€” check these first if the app fails to deploy
  • Runtime Logs / stderr.log β€” check these if the app deployed but is broken or crashing

Path: hPanel β†’ Websites β†’ Dashboard β†’ Deployments

πŸ—„οΈ Connecting a Database

Node.js apps often need a database to store data. On Hostinger, you can connect to our database or Supabase


To connect to our database, there are two ways:
  1. Create or update the env to:
    DB_HOST=localhost
    DB_PORT=3306
    DB_USER=databaseuser
    DB_PASSWORD=databasepassword
    DB_NAME=databasename
  2. Or use a single string:
    DATABASE_URL=mysql://databaseuser:databasepassword@localhost:3306/databasename
Use the Database Connect Wizard in your Website Dashboard for Supabase and MongoDB Atlas β€” it automatically saves credentials as environment variables and triggers a rebuild.

🏠 Setting Up Node.js on Hostinger

βœ… Plan Availability

Node.js applications are available on: Business Hosting Cloud Hosting

  • Up to 5 Node.js applications per plan
  • Agency plan users can only use ZIP upload (no GitHub integration)
  • One hosting plan can connect to only one GitHub account at a time
  • GitHub connection can only be added by the website owner (not shared access users)

πŸ†• How to Add a New Node.js Website

  1. Log in to hPanel at hpanel.hostinger.com
  2. Go to Websites and click Add Website
  3. Choose Node.js Web App as the website type
  4. Select your deployment method: GitHub or Upload ZIP
  5. Configure your settings (Node.js version, framework, root directory)
  6. Deploy and monitor the Build Logs for any errors

πŸ“– Full guide: How to add a Node.js Web App in Hostinger

πŸ”„ Deployed app directory

  1. /domain.tld/hbuilds/versions β€” stores each individual build version
  2. /domain.tld/hbuilds/current β€” a symlink that always points to your active (latest) build
  3. /domain.tld/hbuilds/current/nodejs/ β€” where your active Node.js build files live
  4. /domain.tld/public_html/.htaccess β€” auto-generated to route traffic correctly to /hbuilds/current
  5. /domain.tld/hbuilds/current/public_html/.htaccess β€” the .htaccess used for the website like adding CSP, redirection, etc

πŸ”§ Troubleshooting Guide

πŸ—ΊοΈ General Troubleshooting Approach β€” Start Here

Before diving into specific errors, always follow this two-step approach:

  1. App fails to deploy / won't start? β†’ Check the Build Log first.
    The Build Log records everything that happens during deployment. If something went wrong during installation or the build process, the error will be here.
    πŸ“ hPanel β†’ Websites β†’ Dashboard β†’ Deployments β†’ [failed build] β†’ Build Logs
  2. App deployed successfully but is broken, crashing, or showing errors? β†’ Check Runtime Logs or stderr.log.
    These logs capture what happens after the app starts running. If the app crashes, throws errors, or behaves unexpectedly, the cause will be here.
    πŸ“ Runtime Logs: hPanel β†’ Websites β†’ [Node.js site] β†’ Dashboard β†’ Runtime Logs
    πŸ“ stderr.log: hPanel β†’ /domain.tld/hbuilds/current/nodejs/stderr.log

Simple rule: deployment failure = Build Log. Post-deployment issue = Runtime Log / stderr.log.

πŸ—οΈ Build Errors β€” "Failed to build the application"

BUILD ERROR This is the most common error. It means the deployment engine couldn't complete the build process. Always check the Build Log first.

Common Causes & Fixes

CauseHow to Fix
Wrong Node.js version selected Go to Deployments β†’ Settings and redeploy β†’ match the version in your package.json engines field. Supported: 18.x, 20.x, 22.x, 24.x
package.json not found For GitHub: make sure package.json is committed. For ZIP: ensure it's at the root of the archive, not inside a subfolder
Wrong framework selected In Deployments β†’ Settings, confirm the framework matches your actual project (e.g., Next.js, React, Vue)
Wrong root directory Verify the root directory setting matches where your package.json actually lives
Runtime packages in devDependencies Move packages your live app needs from devDependencies to dependencies in package.json
node_modules included in ZIP Remove the node_modules folder before zipping. Hostinger installs them automatically from package.json
After fixing the issue: go to Deployments β†’ Settings and redeploy β†’ Save and redeploy. Monitor the build logs to confirm success.

πŸ”΄ 5xx Errors (Server-Side Issues)

These errors appear after deployment. The app is running but something is wrong. Check Runtime Logs or stderr.log to find the cause.

503 Service Unavailable

The app is deployed but not responding. Most common right after deployment.

  1. Check resource usage β€” hPanel β†’ Websites β†’ Dashboard β†’ Resource Usage. If CPU/RAM hits the red line, the plan limit was reached. Follow the resource limit guide.
  2. Missing env variables β€” Add a dummy env var in hPanel (e.g., TEST=test) and redeploy. This often resolves the 503.
  3. 503 after GitHub redeploy β€” Try deploying via ZIP upload instead.
  4. Avoid manual .htaccess edits β€” Manual edits + redeploy can trigger 503.
  5. Last resort β€” Deploy as a brand new website on a temporary domain.

502 Bad Gateway / 500 Internal Server Error

The app crashed or is returning errors. Check Runtime Logs or stderr.log first.

  1. Check Runtime Logs: hPanel β†’ Websites β†’ [Node.js site] β†’ Dashboard β†’ Runtime Logs
  2. Check stderr.log in File Manager under domain.tld/hbuilds/current/nodejs/stderr.log
  3. Look for stack traces β€” they show the exact file and line number where the crash happened
  4. Verify .env variables: app must use port 3000, NODE_ENV=production, correct DB credentials
  5. If DB is configured: DB username, database name, and password must match what's in hPanel

🟠 4xx Errors (Client/Config Issues)

403 Forbidden

Usually caused by missing or incorrect .htaccess configuration after deployment.

  • Build files may be stored outside of public_html
  • Check that .htaccess exists inside public_html
  • Confirm it has the correct rewrite/routing rules for your framework (SPA routing, Next.js routing, etc.)

404 Not Found

  • Check that .htaccess routing rules are correct for your framework
  • Verify the output directory setting matches where your build files are generated
  • If you recently changed from a temporary domain to a real domain, update .htaccess rules accordingly

πŸ”‘ Environment Variable Issues

If env variables aren't being applied even after setting them in hPanel, use this manual workaround:

Step 1: Create .env file manually

  1. Open File Manager in hPanel
  2. Go to your website root (usually domain.tld/hbuilds/current/nodejs/)
  3. Create a file named .env
  4. Add your variables (one per line): API_KEY=12345

Step 2: Secure the .env file

Add this to the very top of your .htaccess file:

<Files .env>
  Order allow,deny
  Deny from all
</Files>

Step 3: Restart the application

Via SSH: touch tmp/restart.txt
Or via hPanel: Website Dashboard β†’ Restart button

The message "injecting env (0) from .env" in runtime logs is NOT an error β€” it just means 0 variables were loaded from a .env file. Hostinger injects variables via hPanel separately.

πŸ“‹ How to Read Logs

πŸ“¦ Build Logs β€” use when the app fails to deploy

These record everything that happens during the deployment process. If the app never started, start here.

πŸ“ hPanel β†’ Websites β†’ Dashboard β†’ Deployments β†’ [failed build] β†’ Build Logs

πŸ–₯️ Runtime Logs β€” use when the app deployed but is broken

These record what happens while the app is running. Crashes, unhandled errors, and missing modules show up here.

πŸ“ hPanel β†’ Websites β†’ [Your Node.js site] β†’ Dashboard β†’ Runtime Logs

Note: If deployed before Runtime Logs was released, redeploy first. Static sites (Vite, React static) won't produce runtime logs β€” only server-side apps do (Next.js, Express).

πŸ’₯ stderr.log β€” use for crash logs

This file captures crash output. If the app starts then immediately dies, this is where to look.

πŸ“ hPanel β†’ File Manager β†’ domain.tld/hbuilds/current/nodejs/stderr.log

If empty: ask customer to redeploy and re-check, or check stdout.log instead.

If the log output is confusing or hard to read, copy the relevant lines (remove any passwords or API keys first!) and paste them into an AI tool like ChatGPT or Claude. Ask it to explain the error in plain English β€” it's surprisingly good at this.

πŸ—„οΈ Database Connection Issues

Error MessageCauseFix
"Access denied for user" Wrong DB username or password Verify credentials in hPanel and ensure the MySQL user is linked to the database
"Cannot connect to MySQL server" Wrong host or port Set host to localhost and port to 3306
"DATABASE_URL is not defined" Missing environment variable Add the variable in hPanel β†’ Environment Variables, then restart the app
App crashes after DB config change New env vars not loaded Restart app: hPanel β†’ Restart, or SSH: touch tmp/restart.txt

πŸ™ GitHub Integration Issues

One hosting plan can only be connected to ONE GitHub account at a time. All Node.js websites on that plan share the same GitHub account.
  • Can't add GitHub connection β€” Only the website owner can add it. Shared access users cannot.
  • Redeploy via GitHub triggers 503 β€” Use ZIP upload method as a workaround.
  • Missing repository access β€” Verify the GitHub account connected to the plan has access to the repository.
  • Auto-deploy not triggering β€” Check that the webhook is active in your GitHub repository settings.

πŸ’» "Can I run npm commands via SSH?"

On Business and Cloud Hosting (shared hosting), npm is NOT available via SSH. It's only available on VPS plans.

If you need to reinstall dependencies or run npm scripts, the solution is to Redeploy your application β€” this triggers the platform to read your package.json, reinstall all packages, and rebuild automatically.

πŸ“– Guide: How to redeploy a Node.js application

βœ… Pre-Support Checklist

Before escalating or contacting support, go through this checklist:

πŸ—οΈ Build / Deployment Issues

  • Checked the Build Log for ERROR lines
  • Node.js version in hPanel matches the engines field in package.json
  • package.json exists at the project root (not inside a subfolder)
  • Framework selection in hPanel matches the actual framework used
  • Root directory setting is correct
  • Runtime packages are in dependencies, not devDependencies
  • ZIP upload does NOT include the node_modules folder

πŸ”΄ Runtime / 5xx Errors

  • Checked Runtime Logs and/or stderr.log for error messages
  • App is configured to listen on port 3000
  • NODE_ENV is set to production
  • All required environment variables are set in hPanel
  • Database credentials match what's configured in hPanel
  • Resource usage checked β€” CPU/RAM not hitting plan limits
  • App restarted after environment variable changes

🟠 4xx Errors

  • .htaccess exists inside public_html
  • .htaccess has correct routing rules for the framework
  • Domain is correctly pointed (not still pointing to temporary domain)
  • Output directory setting matches where build files are generated

πŸ™ GitHub Integration

  • GitHub connection was added by the website owner (not a shared access user)
  • The connected GitHub account has access to the repository
  • Only one GitHub account is connected to the hosting plan
  • If 503 after GitHub redeploy β€” tried ZIP upload as alternative

πŸ“Œ Quick Reference