title: NodeJS - Send socket when paramaters from url is received
body: <p>I am trying to send a socket using socket.io when the get request <strong>?server</strong> in the url is received. I am loading the buttons which will redirect the page from a json file sent by the node.js server.</p>
  
  <p>When the get request is received, a socket is sent to the server. The problem is on the serverside the socket isn't being received for some reason.</p>
  
  <p><strong>index.html</strong></p>
  
  <pre><code>    &lt;script src="jquery.js"&gt;&lt;/script&gt;
      &lt;script src="jquery-ui.js"&gt;&lt;/script&gt;
      &lt;script src="jquery-ui.min.js"&gt;&lt;/script&gt;
      &lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
      &lt;link href="https://fonts.googleapis.com/css?family=Bungee|Roboto" rel="stylesheet"&gt;
  
      &lt;div id="channels" style="height: 100%; width: 100%; position: absolute; top: 0%; left: 0%; background-color: #000;"&gt;&lt;/div&gt;
  
      &lt;style&gt;
          html {
              color: #fff;
          }
      &lt;/style&gt;
  
      &lt;script&gt;
  
  function getParameterByName(name, url) {
      if (!url) {
        url = window.location.href;
      }
      name = name.replace(/[\[\]]/g, "\\$&amp;");
      var regex = new RegExp("[?&amp;]" + name + "(=([^&amp;#]*)|&amp;|#|$)"),
          results = regex.exec(url);
      if (!results) return null;
      if (!results[2]) return '';
      return decodeURIComponent(results[2].replace(/\+/g, " "));
  }
  
      var socket = io();
  
      socket.on("server", function(server){
          console.log(server);
          $("#channels").append("&lt;a href='?server="+server+"'&gt;&lt;h1&gt;"+server+"&lt;/h1&gt;&lt;/a&gt;");
      });
  
      var server = getParameterByName("server");
              console.log("Connecting to",server);
              socket.emit("connect", server);
  
      &lt;/script&gt;
  </code></pre>
  
  <p><strong>server.js</strong></p>
  
  <pre><code>   process.stdout.write('\033c'); // Clear the console on startup
  
  var
     express = require("express"),
     app = express(),
     http = require("http").Server(app),
     io = require("socket.io")(http),
     path = require("path"),
     colorworks = require("colorworks").create();
  
        http.listen(8080, function(){
           console.log("server is running on port 8080");
        });
  
              app.use(express.static(__dirname + "/public2"));
  
              app.get("/", function(request, response){
                  response.sendFile(__dirname + "/public2/index.html");
                  console.log("Served file to client");
              });
  
      var database = require("./json/database_original.json");
      var number_servers = Object.keys(database.servers).length;
  
  io.on("connection", function(socket){
  
      for (var i = 0; i &lt; number_servers; i++){
          socket.emit("server", database.servers[i].serverJOIN);
          console.log("Server name sent: " + database.servers[i].serverJOIN);
      }
  
      socket.on("connect", function(server){
          console.log("Socket received: " + server);
      });
  
  });
  </code></pre>
  
  <p><strong>database.json</strong></p>
  
  <pre><code>    {
          "servers": [
              {
                  "serverNAME": "server1",
                  "serverJOIN": "@server1"
              },
              {
                  "serverNAME": "server2",
                  "serverJOIN": "@server2"
              },
              {
                  "serverNAME": "server3",
                  "serverJOIN": "@server3"
              }
          ]
      }
  </code></pre>