How to serve an image using nodejs

前端 未结 11 1438
渐次进展
渐次进展 2020-11-22 08:18

I have a logo that is residing at the public/images/logo.gif. Here is my nodejs code.

http.createServer(function(req, res){
  res.writeHead(200,          


        
11条回答
  •  萌比男神i
    2020-11-22 09:12

    var http = require('http');
    var fs = require('fs');
    
    http.createServer(function(req, res) {
      res.writeHead(200,{'content-type':'image/jpg'});
      fs.createReadStream('./image/demo.jpg').pipe(res);
    }).listen(3000);
    console.log('server running at 3000');
    

提交回复
热议问题