It is sometimes useful to have the date and time from the server side instead of the client side. We're usually interested in the client-side time zone, but this isn't always the case. For example, if we create a dashboard for a web-hosting platform, it could be helpful to display the time as it appears on the server.
In this recipe, we will create a server-side clock that updates the user interface in real time so that we always know what time the server thinks it is.
To create a server-side clock that emits data to the client-side, follow these steps:
server.jsfile that emits a new date string every second. To do this, we will set an interval of
1000ms and emit
new Date()for this interval. ...