Essentially, im trying to retrieve “img source” which is basically file path to the imgs: e.g. “assts/imgs/image1.png” (stored on my node server in an array called “photos” as an impromptu database.)
I’m using the following directory structure:
{
root
├── /assts
│ ├── /imgs # All img stored here
│ ├── /scrpts
│ │ └── index.js #client-side js
│ └── /stls
│ └── style.css #client side CSS
├── index.html
├── server.js
├── package.json
}
However, all my attempts thus far in trying to fetch the “img src” it via client-side js has results in error 404.
I’ve tried manually checking the url “http://localhost.8080/photos” but ive only gotten “CANNOT GET/” errors.
This is the client js to fetch the JSON objects:
```
addEventListener('click', async function(event) {
try {
let response = await fetch('/photos');
if (!response.ok) {
throw new Error(`${response.status}`);
}
let photos = await response.json();
```
And the following is the server js:
```
const express = require("express");
const app = express();
const photos = [
{"source": "assts/imgs/image1.png"}
];
app.get('/photos', (req, res) => {
try{
res.json(photos);
}
});
app.listen(8080);
```
I’ve tried app.use(express.static((__dirname, 'assts')));
but it doesnt work.