Ad
Update Client-side Information From Server, Without Sending A Request Each Time
I am currently developing my own desktop clock app and after successfully receiving the current date and time via custom API and locally, I've come to the point where serious complications may occur in the future.
With the current implementation of (local-time), the time is updated locally - every minute per app instance.
It would be unnecessary silly if I try to achieve the same for the (server-time) -> to send a GET request each minute to the Server from every existing app instance...
So, here comes my question..
What are the more efficient alternatives?
P.S. The server environment is Node.js. The received time is in the form of a JSON.
Ad
Answer
you can try this code
const serverTime = new Date(); // lets say this is time from server
const timer = (time) =>{
setTimeout(()=>{
time.setSeconds(time.getSeconds() + 1);
console.log(time)
timer(time);
},1000)
}
timer(serverTime);
Ad
source: stackoverflow.com
Related Questions
- → Maximum call stack exceeded when instantiating class inside of a module
- → Browserify api: how to pass advanced option to script
- → Node.js Passing object from server.js to external modules?
- → gulp-rename makes copies, but does not replace
- → requiring RX.js in node.js
- → Remove an ObjectId from an array of objectId
- → Can not connect to Redis
- → React: How to publish page on server using React-starter-kit
- → Express - better pattern for passing data between middleware functions
- → Can't get plotly + node.js to stream data coming through POST requests
- → IsGenerator implementation
- → Async/Await not waiting
- → (Socket.io on nodejs) Updating div with mysql data stops without showing error
Ad