So what you could do is update it based on an event that happens in the backend.
Front End
<div id="updating">sample text</div>
<script>
var updatedDiv = document.getElementById("updating")
document.addEventListener("DOMContentLoaded", function(event) {
var socket = io();
socket.on(‘update event’, data => {
updatedDiv.innerHTML = data;
});
});
</script>
Back End
var io = require('socket.io')(http);
function runme() {
io.emit(‘update event’,’this is the changed text’);
}
When the function is running, and the update event is running, the data in the html element will change. I hope that this solves your problem!