title: What is the correct way to send 2 parameters in socket.io using lambdas? (I get undefined when printing in client and server)
body: <p>I am new to sockets.io and I am trying to send 2 values when using <code>socket.on()</code>. My problem is that I dont get any errors when sending 2 values from the client to the server. I tried printing the values, however, I get undefined on both parameters (<strong>in both the client and the server</strong>). I would want to know what is the correct way of sending the 2 values from client-server <code>(socket.on())</code> and back to server-client <code>(socket.emit())</code> since I dont get ANY errors.</p>
  
  <p><strong>NOTE:</strong> everything works fine when using only 1 value in the sockets!</p>
  
  <p>My index.html is:</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.io - chart.js example&lt;/title&gt;
    &lt;script type="text/javascript "src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.0/Chart.bundle.min.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;Analisis de Sentimientos&lt;/h1&gt;
      &lt;form&gt;
          Ingresar Nombre del Lugar: 
          &lt;input id="lugar" type="text" name="Lugar"&gt;&lt;br&gt;
          &lt;input type="submit" value="Analizar" onclick="recivir()"&gt;
      &lt;/form&gt;
      &lt;canvas id="chart"&gt;&lt;/canvas&gt;
      &lt;canvas id="chart2"&gt;&lt;/canvas&gt;
  
      &lt;script type="text/javascript"&gt;
  
      var lugar = "";
      function recivir(){
          lugar = document.getElementById("lugar").value;
      }
  
      var socket = io.connect();
      var ctx = document.getElementById('chart').getContext('2d')
      var data = {
          labels: [''],
              datasets: [{
              data: [0],
              label: 'POSITIVO',
              backgroundColor: 'rgb(0,0,170,0.8)',
              render: 'percentage'
          }]
      }
  
      var options = {
              plugins: {
                  labels: {
                      render: 'label',
                      }
                  },
                  showActualPercentages: true,
              }
  
  
      var chart = new Chart(ctx, {
          type: 'bar',
          data: data,
          options: options
      })
  
      chart.canvas.parentNode.style.width = '30%';
  
      socket.on('temperature', function (value, lugar) {
          var length = data.labels.length
  
          if (length &gt;= 5) {
              data.datasets[0].data.shift()
              data.labels.shift()
          }
  
          data.labels.push('');
          data.datasets[0].data.push(value)
  
  
          chart.update()
      })
  
      var socket2 = io.connect();
      var ctx2 = document.getElementById('chart2').getContext('2d')
      var data2 = {
          labels: [''],
              datasets: [{
              data: [0],
              label: 'NEGATIVO',
              backgroundColor: 'rgb(170,0,0,0.8)',
              render: 'percentage'
          }]
      }
  
      var options2 = {
              plugins: {
                  labels: {
                      render: 'label',
                      }
                  },
                  showActualPercentages: true,
              }
  
  
      var chart2 = new Chart(ctx2, {
          type: 'bar',
          data: data2,
          options: options2
      })
  
      chart2.canvas.parentNode.style.width = '30%';
  
      socket2.on('temperature', function (value, lugar) {
          var length = data2.labels.length
  
          if (length &gt;= 5) {
              data2.datasets[0].data.shift()
              data2.labels.shift()
          }
  
          data2.labels.push('');
          data2.datasets[0].data.push(value)
  
          chart2.update();
  
          if(((data.datasets[0].data[1] == data.datasets[0].data[2]) &amp;&amp; (data.datasets[0].data[2] == data.datasets[0].data[3])) 
          &amp;&amp; ((data.datasets[0].data[1] &gt; 0) &amp;&amp; (data.datasets[0].data[2] &gt; 0) &amp;&amp; (data.datasets[0].data[3] &gt; 0)) 
          &amp;&amp; ((data2.datasets[0].data[1] == data2.datasets[0].data[2]) &amp;&amp; (data2.datasets[0].data[2] == data2.datasets[0].data[3])) 
          &amp;&amp; ((data2.datasets[0].data[1] &gt; 0) &amp;&amp; (data2.datasets[0].data[2] &gt; 0) &amp;&amp; (data2.datasets[0].data[3] &gt; 0))){
              socket.close();
              socket2.close();
          }       
      })
    &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My server.js is: </p>
  
  <pre><code>'use strict'
  
  const http = require('http')
  const path = require('path')
  const EventEmitter = require('events')
  const express = require('express')
  const socketio = require('socket.io')
  const port = process.env.PORT || 8888
  
  const app = express()
  const server = http.createServer(app)
  const io = socketio(server)
  const events = new EventEmitter()
  let x = 0;
  
  app.use(express.static(path.join(__dirname, 'public')))
  
  io.on('connect', socket =&gt; {
    events.on('temperature', ({value, lugar}) =&gt; {
      console.log(value); //this equals undefined
      console.log(lugar); //this equals undefined
      socket.emit('temperature', {value,lugar})
    })
  })
  
  // This function will be changed for the J5 sensor event
  // sensor.on('change', function () {
  //   events.emit('temperature', this.celsius)
  // })
  //
  setInterval(() =&gt; {
  
      if(x &lt; 30){
          x++;
      }
  
      const temperature = x;
  
      events.emit('temperature', {temperature,x});
  }, 1000)
  
  server.listen(port, () =&gt; console.log(`Listening on port ${port}`))
  </code></pre>