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

前端 未结 2 1657
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

提交回复
热议问题