I\'m trying to learn nodejs and I thought the best way to do this would be to try doing some stuff without using express or any other non-core modules. I\'m stuck on trying
If you do response.write('
as mentioned above the image file would be sent only when browser sends GET for the image. It would become multi-part request.');
Or you can do it like this. It is possible to send your image in binary form in HTML. Use :
where imagedata is a base64 encoding of gif image. So do this in node.js :
//Write text in response.
content = get-image-file-contents; //store image into content
imagedata = new Buffer(content).toString('base64'); //encode to base64
response.write('
');//send image
response.end();
Check here for correct image conversion NodeJS base64 image encoding/decoding not quite working
This sends one response which sends both text and image. Only one header is required for response response.writeHead(200, {'content-type':'text/html'});