WebSocket

Step 1: To show the chat messages on the page, go to script.js, and add the following below adding an event listener:
let request = new XMLHttpRequest()
request.addEventListener(`load`, showMessages)
request.open(`GET`, `/messages`)
request.send()
The function showMessages will get called when the server responds with the messages. Add the following at the bottom:
function showMessages() {
  let messages = this.response
  console.log(messages)
}
Send a few chat messages, refresh the page, and view the messages in the browser console. You will show the messages on the page in the next step.
Last section Next step