Answer the question
In order to leave comments, you need to log in
Why doesn't my method of displaying an image in a browser on nodejs work?
The code -
var http = require('http').createServer().listen(8080);
var fs = require('fs');
http.on('request', function(req, res){
res.writeHead(200);
var file = fs.createReadStream('logo.gif');
file.pipe(res);
});
Answer the question
In order to leave comments, you need to log in
Everything works, put the image in the same folder, run it, open 127.0.0.1:8080 Here, of course, HTTP headers are not formed, but it works. Most likely your node process does not have access to the file, check the permissions, if it does not help, then write the file name like this './logo.gif'.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question