Skip to content
← Back to Community
Is there a way to make a live updating server?
Profile icon
RohilPatel

So I have a question: Can I make a webpage that updates live?

So, say, I have a user click a button, and the number is displayed on their screen every time he clicks it. Is it possible for another user to have the same setup, however see how many times the first person has clicked the button live?

If so, please give me a tutorial for this, as I'm not the best at coding quite yet. Thanks a lot!

Answered by Vandesm14 [earned 5 cycles]
View Answer
Voters
Profile icon
haqilRosli
Profile icon
RohilPatel
Comments
hotnewtop
Profile icon
Vandesm14

You need an Expressjs server with websockets set up to increment a database value each time. Do you have any experience in Expressjs or websockets?

Profile icon
RohilPatel

Not really @Vandesm14

Profile icon
Vandesm14

@RohilPatel Are you more familiar with Python web servers?

Profile icon
RohilPatel

No, I am most fluent in Html, js, and css [email protected]

Profile icon
Vandesm14

@RohilPatel Ah. So I suggest that you learn Expressjs in order to get a server up and running. Once you have that, feel free to contact me on Discord Vandesm14#3364. I'll be more than happy to help you get the web app set up.

Profile icon
RohilPatel

@Vandesm14 I friended u on discord. And I may need help now making a server. Could you help with that?

Profile icon
Vandesm14

@RohilPatel Sure. For now though, mark my comment as the answer
Don't worry, I'll be helping you on discord. It's just so others know this is answered.

Profile icon
MrEconomical

@Vandesm14 tbh I prefer http for anything thats not sustained

Profile icon
RohilPatel

Explain.... @MrEconomical

Profile icon
MrEconomical

@RohilPatel um well websockets are usually used when connections need to be sustained and messages need to be sent back and forth very fast, for example something like a multiplayer game might use websockets. HTTP requests are just one time, you send it and you get a response.

Profile icon
Vandesm14

@MrEconomical Http? Expressjs is an http server for NodeJS.

Profile icon
MrEconomical

@Vandesm14 my bad

Profile icon
RohilPatel

@MrEconomical do you have any examples?

Profile icon
MrEconomical

@RohilPatel something like this

client: https://repl.it/@MrEconomical/xmlreq-testing
server: https://repl.it/@MrEconomical/http-server

if you hit run on the client you can see it gets something back from the server

Profile icon
MrEconomical

@RohilPatel that client was made in node.js the same thing would work in normal html / css / js except you don't need require() because xmlhttprequests are a built-in thing

Profile icon
Vandesm14

@MrEconomical Yes, polling is also a thing. Websockets are better as you're not using as much resources on the client to constantly poll the server for new data. Also, http, like you said, is generally a one-time thing. It's not meant for live updates, which is the goal here.

Profile icon
MrEconomical

@Vandesm14 oh I thought all he needed was updating a number once

Profile icon
RohilPatel

@MrEconomical so are you saying that I can import data from two different websites?

Profile icon
MrEconomical

@RohilPatel disregard everything I said I was just mentioning an alternative that doesn't seem to be good in your case

Profile icon
RohilPatel
Profile icon
Coder100

Yes. Here is how i did it:

  1. Set up server
  2. Set up html
  3. Set up socket.io
  4. Listen for handlers
  5. Success!
    All of it is documented. Just look at my code right here: https://repl.it/@coder100/4rohilpatel
    The ‘game’ is here:
    https://4rohilpatel.coder100.repl.co/
    Mark as correct answer if this was helpful!
    Also, as a plus, the click amount saves until the repl shuts down after 1 hour of no inactivity!
Profile icon
AdCharity

btw if you don't want to deal with all that: use Firebase