Host a Node.js app in cPanel and connect it to its database
Updated 27 Nov 2026
Our hosting plans can run Node.js apps through cPanel's Setup Node.js App. This guide sets one up and connects it to a MySQL database.
For bigger apps, or full control of the server, a Cloud VPS is better: see Host a Node.js app on your VPS.
1. Upload the app
Upload your project (without node_modules) to a folder in your home directory, for example ~/myapp, with File Manager (upload a ZIP and Extract) or FTP: see Upload your website. Keep it outside public_html.
2. Create the application
In cPanel open Setup Node.js App › Create Application, and fill in:
- Node.js version: the version your app needs.
- Application mode: Production.
- Application root: the folder with
package.json, for examplemyapp. - Application URL: the domain or subdomain that should open the app.
- Application startup file: for example
app.js,server.jsorindex.js.
Press Create. Then press Run NPM Install and wait for it to finish.
Your app must listen on the port it is given: use process.env.PORT in your code, not a fixed number.
3. Create the database
Every database name and user on your account starts with your cPanel username and an underscore (your prefix), for example dukabora_. In cPanel open MySQL® Databases:
- Create New Database: type
appdb. It becomesdukabora_appdb. - Add New User: type
appdb, set a strong password, and save it. - Add User To Database: choose the user and the database, press Add, tick ALL PRIVILEGES, then Make Changes.
Step 3 is the one most people miss: without it you get Access denied even with the right password. More: Create a MySQL database.
Have data from elsewhere? Import your .sql file in phpMyAdmin › your database › Import.
4. Set the connection details
In your .env (or wherever your settings are), use your own prefix:
DB_HOST=localhost
DB_PORT=3306
DB_NAME=dukabora_appdb
DB_USER=dukabora_appdb
DB_PASSWORD=the-password-you-set
Or add them as Environment variables in Setup Node.js App. Use one place, not both.
5. Restart
In Setup Node.js App, press Restart. Restart after every change: Node keeps its settings in memory, so an edited .env does nothing until the app restarts.
From the Terminal instead: touch ~/myapp/tmp/restart.txt.
When it does not work
Read the app's log first: stderr.log in the application root, or the logs in ~/logs.
| Error | Fix |
|---|---|
ER_ACCESS_DENIED_ERROR |
Wrong user or password, or the user was never added to the database (step 3). The old server's user names do not exist here. |
ER_BAD_DB_ERROR / Unknown database |
The database name must include your prefix. |
ECONNREFUSED 127.0.0.1:3306 |
Use DB_HOST=localhost and port 3306. |
| "We're sorry, but something went wrong" / app could not be started | The app crashed at start: check the startup file name, run Run NPM Install, read stderr.log. |
Cannot find module |
Dependencies are missing for this Node.js version: Run NPM Install again. |
| Changes have no effect | The app was not restarted. |
Kwa Kiswahili
Kwenye cPanel › Setup Node.js App › Create Application: chagua toleo la Node.js, folda ya app, anwani (URL) na faili la kuanzia, kisha Run NPM Install. Database: jina na mtumiaji vianze na cPanel username_, na usisahau Add User To Database na ALL PRIVILEGES. Kila ukibadilisha kitu, bonyeza Restart.
Still need help? Open a ticket and we will reply.