How can I assign a call back function for event 'data' and give it more then 1 standard parameter ? Here is my script :
var http = require('http');
var server = http.createServer().listen(8080);
server.on('request', onRequest);
server.on('listening', onListening);
function onRequest(request, response)
{
response.writeHead(200);
request.on('data', function(){onReqData(data,res)});
request.on('end', onReqEnd);
}
function onReqData(data, response)
{
console.log('Request : ', data.toString());
response.write('Write : ' + data.toString());
}
function listen()
{
console.log('--- / Server runs on 8080 / --- ');
}
function onReqEnd()
{
console.log(' - - - / The end of request / - - - ');
}
I don't like the syntax where the body of the callback function is in the .on() block.
So when I'm trying to assign a callback like this :
request.on('data', onReqData); without declaring function incoming params (function onReqData(){...} )
I have an error which tells me that response is undefined
request.on('data', function(){onReqData(data,res)});
Gives me an error that data is undefined.
Any help will be greatly appreciated !