I dont understand how to host a website that uses node.js (and socket.io)

I have created a simple chat room using socket io and the " WebSockets in 100 Seconds & Beyond with Socket io" tutorial. It works fine and I actually want to try hosting it as a website.
Now I am confused by there being the node js server. I made it listen to port 8080.
Should i now try to host an apache server while the node.js server runs? Or is it a two in one thing?
I am a beginner in javascript/node js/web dev and appreciate easy-to-understand answers that give a good overview (since I feel like I understand some concepts very wrong)

Hi @LostProgrammer welcome!

Hmmm… don’t take me wrong , but anyone who is starting with coding that is capable to make a proper chat application for the first time in one go after just 9 min video…

Don’t feel discouraged - trying is not a bad thing and experimenting might be frustrating but also rewarding some times.

But it is likely you are trying to fly to soon. And well… try to picture what happens to the chick when jumping into the air when still unready…

My first comment? Well, why not trying our resources first if you haven’t yet?

Just for the start, socket io is a hard library to pick up. It is still minimalistic, unopionated library that requires a lot of coding of (security) guards and error handling from scratch. And I haven’t said anything about debugging it…

If you are new to coding as you said, still want to build a nice example for employers to get mad about you but want to think of an easier project to start:

  • Don’t rush it! It will come eventually but get a good training first!
  • There are many examples and courses that focus on using socket with node express. We teach node / express in Freecodecamp. Here you will also find an introduction to several things like best practices, OO coding, security, etc… all that basic knowledge required to build that sort of applications, no matter the tool (Apache, Django, etc… all are based on similar principles). And more importantly, a community of people who can help.
  • You can also follow the advice of the video: there are other more configurable applications (he mentioned Firebase and several other ones) that could do the trick.

(DISCLAIMER: I don’t have professional experience with sockets but I have done several exercises and projects with the technology)

But let’s say you have enough knowledge. Or better, that you want to have something to show off for potential employers.

Perfect justification!

Well - let’s start by clarifying that the server of your socket library might not be the same as the server of your site (your client site): socket io starts a server covering the full duplex connection - EDIT: usually mounted on another server running under the http protocol - (see video), while for your site (ie. the place where your users will interact with the browser) you could rely on an a connection based on the http protocol for which you might need another http server.

Both servers should be reading inputs from each other.

On your site, subscribed users will input messages to be posted to other users. Those posted messages will be passed from your client’s site to the socket server to be either broadcasted or sent to specific users. The socket server will eventually pass the received messages to the client for other users to see them.

Differently to other ways of communication, with socket io all the exchange will happens in “real time” (or close to…).

The Apache server… it seems like you are using WordPress? Well, that is your site server so you might not need the node.js server suggested in the video. But then you have to find a way to connect your socket server to your Apache server and set it in your whole application. And this is… well, I don’t know. I haven’t done it so I cannot say how hard that could be. But I suspect it won’t be straightforward.

Do you see?

@LostProgrammer

In case you want to go ahead though (which is valid), you could certainly find a way to connect your Apache server and your socket server. I did a very quick research and found things like proxys as the way to go, but I also found on Internet one solution consisting in few lines of code by calling the corresponding servers on both sides.

Then you will have to start both servers and check that both are alive. That can be done if your hosting place allows you access to node.js and Apache. You could also have both hosted in different places, one for node.js and one for Apache, if you cannot have the resources all in one place.