I’ve double-checked everything, on the backend and front end it brand has image property, but ejs doesn’t render the valid HTML.
front end code
<img src="<%= brand.image %>" alt="<%= brand.name %> cover" />
brand data
{
_id: 'dodge',
name: 'dodge',
image: 'https://cdn.wallpapersafari.com/56/27/pfEvIh.gif',
createdAt: 2023-05-23T08:24:04.093Z,
updatedAt: 2023-05-23T08:24:04.093Z,
__v: 0
}
following is the HTML rendered by the ejs for img property
<img src alt="dodge cover">
2
Answers
This happened because I changed the image field name to cover from the schema, it means the schema no longer contains any image field that's why it was returning the undefined image value even image contains value.
Check the image property: Make sure the image property you’re using contains the correct path to the image file. Verify that the path is valid and points to the correct location of the image file on your server.