N
N
Nikolai Antonov2015-02-16 02:18:53
JavaScript
Nikolai Antonov, 2015-02-16 02:18:53

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);

});

There is not even a root html element.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Shemsedinov, 2015-02-16
@my-nickname

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 question

Ask a Question

731 491 924 answers to any question