Running A Node.js App On Shared Hosting Via cPanel

tamj

Registered
Sep 12, 2022
4
2
3
Ireland
cPanel Access Level
Website Owner
I realize that doing this would not be so easy.
But lately (I had run Node.js apps successfully on a shared server in the past 2 years) it seems well-nigh impossible.

I can create the app no issues and apparently get it started.
I can SSH into the app's folder - though of course as this is not the terminal window that started the Node.js app and I see no sign of a running Node app, for example a console log message like:

$ NodeApp listening on port 3001 . . .

This document from InMotion Hosting says we can use the command at the top of the Node.js creation window to enter the Node.js application's environment via SSH from one's local machine or via the Terminal feature on the cPanel.
I successfully entered the Node app's environment via this command to Terminal.

I stopped the Node.js app via the cPanel STOP button and then tried to restart it again via the Terminal command:


$ node app.jsnode:events:491 throw er; // Unhandled 'error' event ^
Error: listen EADDRINUSE: address already in use :::3001
at Server.setupListenHandle [as _listen2] (node:net:1432:16)
at listenInCluster (node:net:1480:12)
at Server.listen (node:net:1568:7)
at Object.<anonymous> (/home/zmail/nodeapp/app.js:145:13)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1459:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '::',
port: 3001
}
$


So although "stopped" the app nonetheless hogs the server port 3001, preventing anyone but the server root to start it.

Funnily enough when my website posts AJAX requests to the Node server all I get is a 503 error.
"Service unavailable . . ."

I should mention that I put a redirect into my website's home folder's .htaccess file :

RewriteEngine On
RewriteRule ^nodeapp/(.*) [URL]https://localhost:3001/$1[/URL] [P,L]


The behavior of this app on the server resembles its behavior on a local machine when I neglect to turn on Node.js . . .
 
Last edited by a moderator:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
15,139
2,405
363
cPanel Access Level
Root Administrator
Hey there! Since this is on a shared server, our support is even more limited than usual with NodeJS, which is mentioned here:


You'll need to work directly with the hosting provider to see what limits they have in place on their machine as you almost certainly won't have the same flexibility as you would on a dedicated system.
 

tamj

Registered
Sep 12, 2022
4
2
3
Ireland
cPanel Access Level
Website Owner
Problem is that few hosting companies carry staff with Node expertise.
Their clients using it usually run it on an unshared server and manage the whole admin of it (apart from applying the host's security requirements) for themselves.
It's only in the last 2 years or so that Node.js has been offered by my host. To my knowledge neither DirectAdmin nor Parallels do so.
I am sure there are technical as well as commercial reasons for this.

Please feel free to close this thread.
 

JoseDieguez

Well-Known Member
PartnerNOC
Jan 26, 2016
73
37
68
Chile
cPanel Access Level
Root Administrator
The error 503 you saw, may have been because of the Total processes limit.

i have seen a dozen times, account reaching the limit 40-60-80-100 processes running a nodejs app.
 
  • Like
Reactions: cPRex

tomfree

Member
Oct 26, 2022
7
1
3
Munich
cPanel Access Level
Website Owner
Host and cPanel keep referring user to the other.:oops:

Looks like I need a cheap server I can set up to suit my own needs.
seems to be common problem with node hosting. I have a similar issue that suddently by node app stopped working with similar error. Locally all is perfect... Seems to be cpanel and its hoster configuration related....
 

tamj

Registered
Sep 12, 2022
4
2
3
Ireland
cPanel Access Level
Website Owner
@tomfree

Yes. I had been using Node.js on CPanel a couple of years ago with no hassles.
Now it's just not working.

You can only spend so much time on something.
So I got a cheap VPS to test it on.
More admin to do but at least I'm in control.
 
  • Like
Reactions: tomfree