How to serve an image using nodejs

前端 未结 11 1439
渐次进展
渐次进展 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:05

    You should use the express framework.

    npm install express
    

    and then

    var express = require('express');
    var app = express();
    app.use(express.static(__dirname + '/public'));
    app.listen(8080);
    

    and then the URL localhost:8080/images/logo.gif should work.

提交回复
热议问题