Now that the server side is completed, the client-side script needs to be modified to accommodate the new functionality that has been added:
/** * First, define a function that will initialize the
socket connection and add listeners * to the required events */ const addSocketListeners = () => { /** * The "io" constructor is available to us after
including the socket.io library script in the "index.html" file * Initializing the socket connection is as easy as the
statement below */ const socket = io() /** * An event listener is attached to the "new-
temperature" event * The handler is similar to the handler that was attached
to the GET /temperature API, so in essence, we are
replacing the API call with the socket event...