Initializing NodeJS server example

I saw the next example here

var net = require('net');
var server = net.createServer(function(c) { //'connection' listener
  console.log('server connected');
  c.on('end', function() {
    console.log('server disconnected');
  });
  c.write('hello\r\n');
  c.pipe(c);
});
server.listen(8124, function() { //'listening' listener
  console.log('server bound');
});

So createServer() has an anonymous function as a parameter. The way I see it this function listens and sends back whatever it receives, which is c.

Am I right so far? And where is c coming from?

Thanks!

The c variable is created inside the net.createServer function. c is returned through the callback given as parameter to the createServer function.

Example:

function createServer(callback) {
   var c = "hello world";
   callback(c);
}

createServer(function(c) {
   console.log(c); // Hello world
});

In your case, c is not a string of course. It was just for the example. It's another object: a socket.