Have node.js installed but cant get socket.io to work

supercain

Member
Sep 2, 2021
17
1
3
detroit
cPanel Access Level
Website Owner
Hi,

I have just installed node.js on my shared server. Seems to be working since I get past the 2 tests. However, I cant get to run socket.io after following this tutorial.


1. I created the directory which is the same one where I put my app.js file (the one you use to test node,js)

2. I put the package.json file

3. I installed the packaged express and socket.io which created a directory called node_modules inside the directory where I put app.js.

4. I modified the app.js file according to the instructions from the tutorial but now the node.js tests wont work. Instead of getting the Hello World! NodeJS test message it says it cant find the directory.

5. I created the index file but on the console it says io() is not defined. This seems to be because the path of socket.io.js is wrong and I had to point it to node_modules/socket.io/client-dist since thats where the .js file was created when I installed the module.

6. I deployed the application on cpanel.

Now I get no error on the console but the test chat simply wont work regardless. I guess because of error on step 4 but even with the original app.js I cant get it to work.
Please notice that when I point my browser to mydpmain.com/testchat I get the node.js test message whereas i I point it to mydpmain.com/testchat/ (add the last slash) then I get the test chat page.

All this is very confusing to me and I would appreciate if you put me in the right direction.

Thank you.
 
Last edited by a moderator:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
7,442
1,004
313
cPanel Access Level
Root Administrator
Hey hey! Unfortunately, this is even less supported than NodeJS itself from the earlier guide we worked with, so the only thing I can recommend is to work with the host to see if they can chase down errors. It's one of those "it should just work" type of things if the guide is followed, but it seems like there are other issues with this host causing issues, such as the test application from the earlier post not working the first few times.
 

supercain

Member
Sep 2, 2021
17
1
3
detroit
cPanel Access Level
Website Owner
Okay so now I got it to work. One problem though. After I start the app on the terminal with /opt/cpanel/ea-nodejs10/bin/node index.js
I can access the app at mydomain.com:3000 however as soon as I exit the terminal the app stops working and I cant even access mydomain.com:3000 anymore. Maybe a cronjob will get around this?
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
7,442
1,004
313
cPanel Access Level
Root Administrator
That's expected behavior - you test the app by starting the process in your terminal, which is why the docs say you have to open a new terminal session to run the test command. That command just executes the test application, but you'll want to register your actual app in cPanel in order to keep things running:

 

supercain

Member
Sep 2, 2021
17
1
3
detroit
cPanel Access Level
Website Owner
Hi,

I did register the application from the very beginning but that doesnt change things. Also, am I supposed to be able to access from example.com/myapp ? because if I do so then the chat wont work at all. It only works if I access from example.com:3000 AND the terminal window is still open.
 

supercain

Member
Sep 2, 2021
17
1
3
detroit
cPanel Access Level
Website Owner
I dont think its a problem my host should resolve. It all comes to the correct installation of the socket.io app because Im not even sure if it should reside in the same folder as app.js and all the tutorials are rather confusing.