Netlify function load html file in the same folder

Hi everybody!

I have a problem or misunderstanding of netlify functions. I would like to send an email with mailgun after a successful purchase. I have a handlebars file right next to my netlify function in a folder inside the functions directory like this:
functions >sendEmail> sendEmail.js & email.hbs

In local development with netlify dev I am able to load the hbs file without issue, but in production the email file is not found when the function is called. I have googled and found a thread talking about something similar:

The proposed solutions of using:
const emailTemplateSource = fs.readFileSync( require.resolve("./email.hbs") );

or

const currentDir = process.env.LAMBDA_TASK_ROOT;

const emailTemplateSource = fs.readFileSync( path.join(currentDir, "sendEmail/email.hbs"));

both do not work for me. Maybe someone can point to a simple mistake I did or if their is a possible limitation of netlify functions I am not aware of.

Thank you very much in advance :slight_smile:

Hi @phil30000,

The issue is that your lambda function is not invoked in the same folder/path that contains your bundled files. I do have an example of how/where to access those files here: https://github.com/netlify/function-deploy-test/blob/master/lambda/zipped-function/zipped-function.js#L6-L8. Let me know if that helps.