You can choose either buying a VPS, or setting it up at home.
A domain name is needed for a secure connection, even though this is a public chat. It is possible to run without domain name. If you have multiple public VPS services (more than a chat app), you need a domain name to connect those services.
If setting it up at home, you can choose whether or not you want to publicly show your home ip address.
Once you get a VPS, you will need to install npm in your Linux package manager
$ npm install socket.io express
$ git clone https://github.com/script14/script14.github.io
$ mkdir CHAT
$ cp script14.github.io/js/index.html CHAT //This will be your client-side websocket
$ cp script14.github.io/js/index.js CHAT //This will be your server-side websocket
$ cd CHAT
$ npm init
Now to run the chat-server: $ node index.js
I recommend using a reverse proxy manager, but it is not absolutely necessary unless you are also running other services on your vps.
When running a reverse proxy manager, you should tunnel ports "80" and "443" from the reverse proxy, to the VPS. So that will allow DNS servers to actually resolve to your reverse proxy (let others know that VPS is your server).
If not wanting to do a reverse proxy manager Connect your domain name, from your domain name provider, to your public server VPS ip address via "A".
Now setting up to NOT publicly show your ip address, you WILL need a VPS anyway for. But, the VPS is only for proxying over to (although it doesn't matter that much in this case, because this chat server is lightweight), so you can have a very powerful homelab, and also depublicly list your home ip address.
I recommend something that proxies the connection from your homelab, to the VPS, for example: https://github.com/ekzhang/bore
Then after setting up bore, you can continue the guide on "self-hosting at a public server"
Many Home ISPs are not going to be as extensive and permissive on what ports you can open. It is recommended to do proxying.
You can follow the guide on "self-hosting at a public server", but you will need to port forward ports 443 and 80.