My application is in nodejs with typescript code. Im using express-mailer for sending mail functionality
Below is my structure
-- app.ts (on root)
-- views (on root)
-- /mails/emailSender.ts
app.ts
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
emailSender.ts // emailSender calls mailer.ts using mailer.sendCopy function
mailer.sendCopy('emailStructure/registered_email',
mailOptions, // this is correctly constructed in a separate logic
function(resp_type: any, resp: any) {
if (resp_type == 'err') {
console.log(resp);
}
});
mailer.ts
var express = require('express');
var mailer = require('express-mailer');
app.set('views', path.join(__dirname, '../views'));
app.set('view engine', 'ejs');
exports.sendCopy = function(template, mailOptions, callback) {
app.mailer.send(template, mailOptions, function(err, message) {
if (err) {
callback('err', err);
return;
} else {
callback('success', message);
}
});
};
Even though the path is correct for the views, i still gets the below error
"Failed to lookup view "/registered_email" in views directory "\\my Solution path routing to Views""
I have tried changing the routing paths, moving the directories to different location path, but here the path seems to be correct. What im not able to find is why express is not able to read these views inside emailStructure directory.
I have tried removing the
app.set('views', path.join(__dirname, '../views'));
app.set('view engine', 'ejs');
from mailer.ts but it again gives me the exception as Engine or extension not defined.
With refernce to the below link line 561 render function im also getting the renderOptions.cache as false and hence the execution is not completing.