title: how to solve a ReferenceError in node js (var not defined)
body: <p>I'm new to javascript to I'm probably asking something easy. I'm trying to develop a project using SockJS, nodeJs and ssh2 module of nodeJs.</p>
  
  <p>I'm trying to send a message from Chrome using SockJS library's client side code (websockets) to the NodeJS server and then from the NodeJs to my raspberry pi via ssh2 module. The problem is the following one:</p>
  
  <pre><code>var http = require('http');
  var sockjs = require('sockjs');
  var Connection = require('ssh2');
  
  var c = new Connection();
  var sockserver = sockjs.createServer();
  
  
  var server = http.createServer();
  sockserver.installHandlers(server, {prefix:'/socksvr'});
  server.listen(9999, '0.0.0.0');
  
  sockserver.on('connection', function(conn) {
  
      c.connect({
          // Parameters to connect
      });
  
      //Here goes some code to check that the connection was successful
  
      conn.on('data', function(message) { 
      //this is when Node receives data from client socket
  
          //print somethings
          c.shell(onShell); // This is to send command from node to Raspberry Pi
  
      });
  
      //Here goes the problem 
  
      var onShell = function(err, stream) { 
          if (err != null) {
              console.log('error: ' + err);
          }
  
          stream.on('data', function(data, extended) {
              if (extended === 'stderr'){
                  console.log('STDERR: '+data);
                  conn.write(data);
              }else{
                  if(data != ''){
                      console.log(':' + data);
                      conn.write(':' + data);
                  }
              };        
          });
  
          stream.write(message);
  
      }
  
  }); 
  </code></pre>
  
  <hr>
  
  <pre><code>\server.js:62
  stream.write(message);
               ^
  ReferenceError: message is not defined
  at onShell (C:\Documents and Settings\...\server.js:62:18)
  at C:\Documents and Settings\...\node_modules\ssh2\lib\Channel.js:277:5
  at Parser.&lt;anonymous&gt; (C:\Documents and Settings\...\node_modules\ssh2\l
  ib\Channel.js:123:30)
  at Parser.EventEmitter.emit (events.js:92:17)
  at Parser.parsePacket (C:\Documents and Settings\...\node_modules\ssh2\l
  ib\Parser.js:594:12)
  at Parser.execute (C:\Documents and Settings\...\node_modules\ssh2\lib\P
  arser.js:238:14)
  at Socket.&lt;anonymous&gt; (C:\Documents and Settings\...\node_modules\ssh2\l
  ib\Connection.js:488:18)
  at Socket.EventEmitter.emit (events.js:95:17)
  at Socket.&lt;anonymous&gt; (_stream_readable.js:746:14)
  at Socket.EventEmitter.emit (events.js:92:17)
  </code></pre>
  
  <p>I knew that using <em>message</em> var inside that function wasn't probably going to work but I haven't been able to figure out the solution. I'm probably lacking some knowledge about functions. Any help is appreciated. Thank you.</p>