Node.js Development

Deploying a Node.js Application with MySQL on DomainIndia.com Shared Hosting: A Practical Guide

By the Domain India teamPublished 8 min read
Knowledge base article
Contents (8 sections)

A Node.js app on Domain India shared hosting can use the MySQL databases that come with your plan. You create the database in your control panel, create the app with the panel's Node.js tool, and connect to the database on localhost. This guide covers the database side in detail and the app setup in brief, and shows where a larger app belongs.

Key takeaways

Create a database and user in cPanel's Database Wizard (or DirectAdmin's Account Manager › Databases). Create the app in Setup Node.js App, choose Node.js 22 or 24, and put the database details in the app's environment variables. Connect with the mysql2 package to host localhost, port 3306, using the full prefixed database and user names. Your app must listen on process.env.PORT. Port 3306 is closed to outside connections, so the app must run on the same account as the database.

The full Node.js guide

This page focuses on connecting to MySQL. For every step of creating, starting and troubleshooting the app itself, read How to deploy a Node.js app on shared hosting.

1. What you need

ItemOn our cPanel serversOn our DirectAdmin servers
Node.js app toolSetup Node.js AppNode.js selector plugin
Node.js versions (measured 23 September 2026)20, 22 and 2414 to 24
DatabaseMariaDB, MySQL-compatible, reached on localhostMySQL-compatible, reached on localhost
Database managementphpMyAdminphpMyAdmin

Node.js 20 and older have reached end of life, so choose 22 or 24 if your app supports them. On Webuzo we could not confirm a Node.js tool, so ask support. The panel always shows the current version list.

2. Create the database and user

  1. Open the wizard.
    In cPanel, under Databases, click Database Wizard. In DirectAdmin, open Account Manager › Databases and use the Create Database form; open Advanced mode so you can name the user yourself.
  2. Name the database,
    for example shop. The panel adds your username as a prefix, so it becomes cpaneluser_shop.
  3. Create a user
    such as shopapp with a generated password, and save the password somewhere safe.
  4. Grant privileges.
    Tick only what the app needs, or ALL PRIVILEGES if it also creates its own tables.
  5. Note the four details:
    host localhost, the full database name, the full user name and the password.

Always use the full prefixed names in your code. A missing prefix is the most common cause of "Access denied" and "Unknown database" errors. See How to connect to your MySQL database for the details.

3. Prepare your app

Install the mysql2 driver in your project and commit package.json:

bash
npm install express mysql2

A minimal app.js that reads its settings from environment variables and uses a small connection pool:

javascript
const express = require('express');
const mysql = require('mysql2/promise');

const pool = mysql.createPool({
  host: process.env.DB_HOST || 'localhost',
  port: Number(process.env.DB_PORT || 3306),
  user: process.env.DB_USER,
  password: process.env.DB_PASS,
  database: process.env.DB_NAME,
  connectionLimit: 5,
  charset: 'utf8mb4'
});

const app = express();
app.use(express.json());

app.get('/api/products', async (req, res) => {
  try {
    const [rows] = await pool.query(
      'SELECT id, name FROM products WHERE category = ?',
      [req.query.category || '']
    );
    res.json(rows);
  } catch (err) {
    console.error(err);
    res.status(500).json({ error: 'Database error' });
  }
});

const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Listening on ${port}`));

Three rules matter on shared hosting:

  • Listen on process.env.PORT. The server runs your app behind Apache using Phusion Passenger and passes the port in. A fixed port won't work.
  • Keep the pool small. Your account has a limit on simultaneous database connections. A handful is plenty for a small app.
  • Use placeholders (?) for every value that comes from a visitor, as above. Never build SQL by joining strings.

If you have a React or other front end, run npm run build on your own computer and upload the output, not the source.

4. Create the app and add your settings

  1. Create the app.
    In cPanel, open Setup Node.js App and click Create Application. Choose the Node.js version, set Application mode to Production, set Application root to a folder such as shopapp outside public_html, pick the Application URL and enter app.js as the startup file.
  2. Add environment variables
    in the same form: DB_HOST=localhost, DB_PORT=3306, DB_NAME=cpaneluser_shop, DB_USER=cpaneluser_shopapp, DB_PASS=… and NODE_ENV=production. Save.
  3. Upload your code
    to the application root with File Manager or FTP, including package.json but not node_modules.
  4. Install and start.
    Click Run NPM Install, then Start App, and open your application URL.

Keeping the password in the panel's environment variables means it never sits in a file inside public_html. Restart the app after every change to the code or the variables.

cPanel Node.js application page with the Web Applications tab, a Create Application button and no applications yet
Setup Node.js App in cPanel: Create Application starts a new app.

5. Create your tables

Open phpMyAdmin from your control panel, select the database and run your SQL in the SQL tab, or import a .sql file with Import. The cPanel phpMyAdmin import limit is 50 MB, so split larger files or ask support. If your app uses a migration tool, you can run it from the app's environment over SSH once jailed SSH is enabled (section 7); the app page shows the command that enters that environment.

6. Troubleshooting

ErrorUsual causeFix
Access denied for userWrong password, or a name without the prefixReset the user's password in the panel and use the full prefixed names
Unknown databaseDatabase name without the prefixCopy the exact name from the panel's database list
ECONNREFUSED or ETIMEDOUTHost set to an IP address or remote hostnameUse localhost, with the app on the same account as the database
Too many connectionsPool too large, or connections never releasedLower connectionLimit and use the pool rather than new connections
503 on the app URLThe app failed to startCheck the startup file and the log named on the app's page, then restart

If you can log in to phpMyAdmin with the same user and password, the credentials are right and the problem is in your environment variables or code.

7. Working from your own computer

Port 3306 is closed to outside connections on our shared servers, and adding your IP under Remote Database Access doesn't open it. Use phpMyAdmin, or an SSH tunnel. Jailed SSH access is available on every shared hosting plan (cPanel, DirectAdmin, Webuzo). It is off by default; ask support to enable it for your account. You log in with an SSH key, and tunnels work:

bash
ssh -N -L 3307:localhost:3306 [email protected]

Then point your local tool at 127.0.0.1, port 3307. See Enabling and accessing jailed SSH.

8. Where Domain India fits

Shared hosting suits a small Node.js app with a MySQL database next to your website. Your app shares the account's CPU and memory limits, and it is not a place for background workers. Prices on the cards are live and exclude 18% GST.

cPanel Starter
₹125/mo + GST
  • 25 GB NVMe SSD Storage
  • 50 GB Monthly Bandwidth
  • 1 Website
  • 10 Email Accounts
See plan details

For a production app, the App Platform builds and deploys Node.js apps automatically and includes a PostgreSQL database and SSL. It has no MySQL and no SSH. If you need MySQL with full control, choose a self-managed VPS.

App Starter
₹100/mo + GST
  • 512 MB RAM per app
  • 1 vCPU
  • 5 GB NVMe SSD
  • PostgreSQL Database
See plan details
What database host should my Node.js app use on Domain India shared hosting?

Use localhost, port 3306, with the full prefixed database name and user name from your control panel. The app must run on the same hosting account as the database.

Which Node.js MySQL driver should I use?

The mysql2 package is the common choice. Use its promise API with a small connection pool and placeholders for every value that comes from a visitor.

Which port should my Node.js app listen on?

Use process.env.PORT. The server runs your app behind Apache with Phusion Passenger and routes traffic to that port, so a fixed port does not work.

Where do I put the database password?

In the environment variables section of Setup Node.js App, then restart the app. That keeps the password out of files inside public_html.

Can I connect to my shared hosting MySQL database from my computer?

Not directly, because port 3306 is closed to outside connections. Use phpMyAdmin, or an SSH tunnel once jailed SSH is enabled on your account. Jailed SSH is off by default; ask support to enable it.

Which Node.js versions can I use?

When we checked on 23 September 2026, cPanel offered Node.js 20, 22 and 24, and DirectAdmin offered 14 to 24. Choose 22 or 24, because 20 and older have reached end of life.

Ready to deploy? Follow the Node.js deployment guide, compare cPanel hosting plans, or look at the App Platform for a production app. If your app still can't reach the database, open a support ticket with the exact error.

Run your Node.js app on the App Platform

Deploy from GitHub or with a deploy token, with a PostgreSQL database and free SSL included.

See App Platform plans

Was this article helpful?

Your answer helps us decide what to improve next.

Still need help? Open a support ticket and our team will reply.

Prefer an app? Add this site to your home screen.Get the app