How to serve the image files using express framework in node.js?

前端 未结 2 1658
Happy的楠姐
Happy的楠姐 2021-02-15 16:37

In my application im using express framework to serve the client side files.But while giving background image for the html element.Its showing failed to load given url.

相关标签:
2条回答
  • 2021-02-15 16:48

    If your file directory is like

    /public
        /stylesheets
        /javascripts
        /images
            /logo.jpg
    

    then your public access begins at the /public directory. This means that in order to access the image, the address would be localhost:8080/images/logo.jpg.

    In summary, you had two problems.

    1. Use a forward slash (/), not a backslash (\) in your URLs
    2. You missed including the image directory in the address
    0 讨论(0)
  • 2021-02-15 16:53

    You are also listening on port 8000, but the image you are referencing has port 8080.

    0 讨论(0)
提交回复
热议问题