I have set up a local express server to serve a JSON file, but I am facing an issue with displaying image files located in a local folder. The image paths are included in the JSON object that I want to display in my DOM. However, the response I receive includes string representations of these image paths, which cannot be used directly. What is the most effective way to serve local images from a local server to the frontend?
Visual representation of the problem:
Configuration on my server side:
app.use(express.static(path.join(__dirname, 'public')))
app.use(express.static(path.join(__dirname, 'server/img')))
The structure of my JSON file:
{
"Images": [{
"title": "First Block",
"images": ["server/img/bijay.jpg", "server/img/dance.png", "server/img/ocean.jpg"]
}, {obj2}, {obj3}, {obj4}]
}
Client-side code for displaying images:
<ul>
<li ng-repeat="obj in objArray"><img ng-src="{{obj.images[0]}}"></li>
</ul>
// testing the display of the first image only
Folder structure overview:
The images are stored within the img folder, which is not displayed here to keep the content concise.