title: Socket.io chat app not showing messages in the DOM
body: <p>I'm following the tutorial on socket.io. But I can't print to the dom.</p>
  
  <p>I've tried using vanilla javascript instead of JQuery but it doesn't work either.</p>
  
  <p>Server file</p>
  
  <pre><code>var app = require('express')();
  var http = require('http').Server(app);
  var PORT = process.env.PORT || 3000;
  var io = require('socket.io')(http);
  
  app.get('/', function(req, res) {
      res.sendFile(__dirname + '/index.html');
  });
  
  io.on('connection', function(socket) {
      socket.on('chat message', function(msg) {
          console.log('message: ' + msg);
          io.emit('chat message' + msg);
      });
  });
  
  http.listen(PORT, function() {
      console.log("Magic is happening on http://localhost:" + PORT );
  })
  
  </code></pre>
  
  <p>HTML file</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="ie=edge"&gt;
      &lt;title&gt;Socket test&lt;/title&gt;
      &lt;style&gt;
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { font: 13px Helvetica, Arial; }
        form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
        form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
        form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
        #messages { list-style-type: none; margin: 0; padding: 0; }
        #messages li { padding: 5px 10px; }
        #messages li:nth-child(odd) { background: #eee; }
      &lt;/style&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;h2&gt;Chat&lt;/h2&gt;
      &lt;ul id="messages"&gt;&lt;/ul&gt;
      &lt;form action=""&gt;
          &lt;input id="m" autocomplete="off" /&gt;
          &lt;button&gt;Send&lt;/button&gt;
      &lt;/form&gt;
  
  
      &lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
      &lt;script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"&gt;&lt;/script&gt;
  
      &lt;script&gt;
          $(function() {
              var socket = io();
              $('form').submit(function() {
                  socket.emit('chat message', $('#m').val());
                  $('#m').val('');
                  return false;
              });
              socket.on('chat message', function(msg) {
                  $('#messages').append($('&lt;li&gt;').text(msg));
                  window.scrollTo(0, document.body.scrollHeight);
              });
          });
      &lt;/script&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>The result should show a message in the DOM. </p>
  
  <p>But I can only see the message in the terminal. </p>
  
  <p>What am I missing?</p>