How to serve an image using nodejs

前端 未结 11 1265
渐次进展
渐次进展 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条回答
  •  孤街浪徒
    2020-11-22 09:00

    This may be a bit off-topic, since you are asking about static file serving via Node.js specifically (where fs.createReadStream('./image/demo.jpg').pipe(res) is actually a good idea), but in production you may want to have your Node app handle tasks, that cannot be tackled otherwise, and off-load static serving to e.g Nginx.

    This means less coding inside your app, and better efficiency since reverse proxies are by design ideal for this.

提交回复
热议问题