How to load html file in a typescript strapi project?

System Information
  • Strapi 4.xx:
  • Window 11:
  • Postgres:
  • Node16.xx:

I am trying to load an HTML email template file, manipulate its contents, and send it out using SendGrid and strapi’s email plugin. But for some reason, the HTML file is be compiled (it’s not included in the dist folder). I get ENOENT: no such file or directory,
If I move the HTML file intro dist folder, it works fine.

This is the code sample :point_down:t4:.
image

The HTML file is in the same directory.

I think you want to put the file in public folder since it’s HTML then require it from there,

1 Like

Thank you very much. This worked fine.

1 Like

Hi what was the url to access the file in your public folder? I am having issues coming up with the right url for the path.

const html_template = readFileSync(path.join(__dirname, '../../../../../public/templates/order_paid.html'), 'utf8');

Results in:

D:\\Devbox\\cbs\\ticketland-ts\\dist\\public\\templates\\order_paid.html'

In the dist folder i dont see any of the public files. So how are they accessible from the build?