mde / ejs

Embedded JavaScript templates -- http://ejs.co

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ENOENT : no such file or directory

gituserjava opened this issue · comments

I am using ejs (v 3.1.9) within a Node JS (v16.0) backend application for generating email templates. I am only using Node JS and I am not using express or any other frameworks.

When running my code, I always get below error. I searched various articles and other issues in the GitHub project but none of them helped. Please advise.

Error:
ENOENT : no such file or director, open ‘/email/body.js’

Code:

export async function sendEmail(toEmailAddresses, subject,
content) {
await ejs.renderFile('/email/body.ejs' { toEmailAddresses,
, content }, async (err, data) => {
if (err) {
console.log("Error is here ");
} else {
console. log("Entered here");
var mailOptions = {
from: FROM_ADDRESS, to: toEmailAddresses, subject: EMAIL_SUBJECT, html: data
};
console. log("Entered here");
await nodemailer.createTransport(MAIL_SERVER_PROPERTIES).sendMail(mailOptions,(error,info)=>{
console. log("Entered here 7777::
if (error) {
console. log("Entered here " + error);
return console. log (error);
}
});
}
});
};

/email/body.js is an absolute path from filesystem root; I'm assuming you wanted ./email/body.js to pull from the current directory?

@RyanZim , I tried the above as well and it did not work. Yes, I need to pull from current directory. My node js start file is also within the same directory. Please advise.

src
   — email
        — email-service.ts
        — body.ejs

What directory are you running node from?

@RyanZim , I fixed it; above suggestion worked!