0

I am trying to display an image in an EJS file and managed to get the file name, however, I would need the relative path, i.e. __dirname + filename to display that image.

Vivek Molkar
  • 3,910
  • 1
  • 34
  • 46

2 Answers2

0

Manage to access the folder using the absolute path, i.e. from the root directory:

("../uploadImages/" + product[i].productImage);
Ayman Arif
  • 1,456
  • 3
  • 16
  • 40
0

Use path.join() for better accessibility:

const path = require("path");
// rest of code
const imagePath = path.join(__dirname, "uploadImages/" + product[i].productImage);
Ayman Arif
  • 1,456
  • 3
  • 16
  • 40
  • thanks Ayman, sorry for being thick, what would I include in path.js? I presume "__dirname"? – omercheema619 Apr 02 '20 at 07:01
  • I presumed you used Node.JS along with EJS. My answer was a result of that.If you want to know more about using node and EJS, you can refer to this. https://stackoverflow.com/questions/5404830/node-js-ejs-including-a-partial – Ayman Arif Apr 02 '20 at 07:08