I need to implement a web server using only net module and socket.write commands. I'm using the following code for sending text files (html, css and etc):
fs.readFile(file,encoding='UTF8', function (err, data) {
if (err) throw err;
var dataToReturn=data.toString();
socket.write('Content-Length:'+dataToReturn.length+'\r\n');
socket.write('\r\n');
socket.write(dataToReturn);
});
Its working fine, but it doesn't work when I need to send image files. What should I do?