title: Socket.io using node.js with no express at all?
body: <p>So I want to create a node.js server using socket.io, but I am more of a beginner, and find the express package rather confusing syntactically. I know that I should learn how to use express and app.js, but plan to do that after I have reached the extent of capability that node.js with only the packages http, js, and socket.io has. I looked online for almost an hour and got nothing to help my problems. The main problem that I am having with socket.io is that on the client side, the function io(); is not working. I even tried redirecting the path of the script link above the body tag to a file in the directory of my server project, but that just returned an error saying that require(); is not a function. I have included some of the files I am using (but NOT ALL of them) under this wall of text. If this is formatted incorrectly, or otherwise incorrect, please forgive me, as this is my first time using stack exchange to ask a question. For this reason, if you have enough reputation to edit this to make it more suitable to the format that you follow here, please do.</p>
  
  <p>First, my server file:</p>
  
  <pre><code>const http = require('http');
  const fs = require('fs');
  const io = require('socket.io')(http);
  
  function socketReq(soc){
      soc.emit("test", {"user":"test", "text":"testing da socket"});
  }
  
  io.on("connection", socketReq);
  
  function server(req,res){
      console.log('A user tried to connect to mazeserver.localtunnel.me'+req.url)
      if(req.url == '/'){
          console.log('Sending html...');
          res.writeHead(200, {"Context-Type":"text/html"});
          fs.createReadStream('./index.html').pipe(res);
      }else if(req.url == '/pong.js'){
          console.log('Sending JS...');
          res.writeHead(200, {"Context-Type":"text/JavaScript"});
          fs.createReadStream('./pong.js').pipe(res);
      }else {
          console.log('Error 404: file .'+req.url+' not found');
          res.writeHead(404, {"Context-Type":"text/html"});
          fs.createReadStream('./404.html').pipe(res);
      }
  }
  
  http.createServer(server).listen(1337);
  console.log('Server created');
  </code></pre>
  
  <p>And now, my main html file:</p>
  
  <pre><code>&lt;html id='html'&gt;
      &lt;head&gt;
          &lt;title&gt;Maze server&lt;/title&gt;
          &lt;center&gt;
          &lt;hr&gt;&lt;br&gt;
          &lt;h1&gt;Welcome to my test server!&lt;/h1&gt;
          &lt;br&gt;&lt;hr&gt;
          &lt;p&gt;This is some text to test&lt;/p&gt;
          &lt;/center&gt;
          &lt;script type='text/JavaScript'&gt;
              document.getElementById('html').style.hide = "true";
              document.onload = function(){
                  document.getElementById('html').style.hide = "false";
              }
              var clicks = 0;
              function clickButton(){
                  clicks++;
                  document.getElementById('clicks').innerHTML = clicks;
              }
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
      &lt;script&gt;
          var socket = io();
      &lt;/script&gt;
      &lt;body&gt;
          &lt;center&gt;
          &lt;button onClick='clickButton();'&gt;Im a button&lt;/button&gt;
          &lt;p&gt;You've clicked me &lt;span id='clicks'&gt;0&lt;/span&gt; times. Ouch!&lt;/p&gt;
          &lt;br&gt;&lt;hr&gt;
          &lt;p&gt;Test canvas:&lt;/p&gt;
          &lt;canvas id='canvas' width='400' height='200'&gt;&lt;/canvas&gt;
          &lt;script src='pong.js' type='text/JavaScript'&gt;&lt;/script&gt;
          &lt;br&gt;
          &lt;br&gt;
          &lt;button onClick='bounce();'&gt;Bounce!&lt;/button&gt;
          &lt;br&gt;
          &lt;button onClick='speed("x");'&gt;Speed up X&lt;/button&gt;
          &lt;button onClick='speed("y");'&gt;Speed up Y&lt;/button&gt;
          &lt;br&gt;
          &lt;button onClick='speed("x"); speed("y");'&gt;Speed up both&lt;/button&gt;
          &lt;br&gt;
          &lt;button onClick='resetXY();'&gt;Reset&lt;/button&gt;
          &lt;br&gt;&lt;hr&gt;
          &lt;/center&gt;
          &lt;p&gt;"Copyrite" &lt;strong&gt;&lt;blink type='EasterEgg' mazeiness='true'&gt;MazeOfEncryption&lt;/blink&gt;&lt;/strong&gt; 2048. Because why the heck not.&lt;/p&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>If more files are needed, please tell me what files I should include, although I <em>do</em> assume that the problem is in one of these 2 files. Thanks in advance,</p>
  
  <p>-Maze</p>