insert some data after response on node.js

I wrote a website tracker for internal use, since Google Analytic don't meet the requirement.

I use node.js with Express to develop that tracking system. Everything works well so far. But I want to confirm is, if there is some problem behind if I insert a log data after response a image.

Thanks!

function image_response(req, res, next){
    var buf = new Buffer([0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00, 0x80, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44, 0x01, 0x00, 0x3b]);
    res.send(200, buf);
    next();
}

app.get('/tracker.gif', image_response, function(req, res){
     // blah blah blah 
     // DB insert codes..
}

Actually the "image_response" is completely end of the response and close the browser connection with client. Afterward, doing the logic to save the data to DB.

You cant modify the result if you did res.send(), use res.write() + res.end() instead.

res.send() is a convenience method of express which unites res.write() and res.end() for easy use. If you want to send data in the response in multiple places you have to use the nodejs' methods write and end on the result.