Hi everyone,
I’m relatively new to the world of JavaScript and web development with only a month of experience. I have built a web server using Node with the Express framework. The server communicates and receives data from a Windows software application that I created a few years ago. The server then passes the data into a database.
The second purpose of the server is to render pages of a web application using the Express ejs layouts method. When a user goes to my domain name, the server looks into the database, retrieves the relevant data and then renders the webpage with the data using the res.render() function.
On one of my pages, I would like the page to update every few seconds for live updates. First, I tried using the reload function with a setInterval function which obviously worked but I’m aware that it’s not the best way of achieving this as it constantly triggers the refresh button on the browser.
It’s been brought to my attention that using the Fetch function is the best way of achieving the updates without the page refreshing. Due to my lack of experience, something is confusing me and I would like some pointers or advice if anyone can help.
So obviously I have coded my server to render the page with all the data whenever a GET request is sent, so the server is rendering the page instead of sending data. Is it possible to achieve the same render method using the Fetch() function. Or would I need to somehow add a new route to my server which sends the webpage the data from the database and then have code which interprets the new data to display it on the page?
Any help would be much appreciated.
Thanks,
Aaron