How do I get the browser to display the image?

前端 未结 1 867
梦如初夏
梦如初夏 2021-01-27 06:19

I want to display an image on a page in the browser but for some reason it will only display the alt tag (in addition to the ordered list below it). The path to the image is cor

相关标签:
1条回答
  • 2021-01-27 07:06

    You're actually serving individual files, that's not the right way. For serving static files using Express, use the Express Static server.

    app.use(express.static('static'));
    

    And move all the static files into a director named static. Else, what you might have to do is:

    app.get("/test.html", (req, res) => {
      res.sendFile("./test.html");
    });
    app.get("/images/test.jpg", (req, res) => {
      res.sendFile("./images/test.jpg");
    });
    
    0 讨论(0)
提交回复
热议问题