Search code examples
node.jsemail-templatesswig-template

Is not a valid directory path


I am starting using node-email-templates to send email with swig template and I am getting this error.

templates/welcome.html is not a valid directory path

Here is my codes from controllers/email.js file.

var path = require('path');
var emailTemplates = require('email-templates');
var templatesDir = path.join(__dirname, '../templates');

exports.send = function(req, res) {

    emailTemplates(templatesDir, function(err, template) {

        if(err)
            console.log(err);

        var locals = {
            username: '[email protected]'
        };

        template('welcome.html', locals, function(err, html, text) {
            if (err)
                res.send(err);
     // Send Email here!
    });
};

Note: The templates folder is in the same directory with controllers folder and which is why I use as '../templates'For path.join.


Solution

  • I carelessly read the documentation by creating welcome.html and just welcome instead of welcome folder. And it should be html.{{ ext }} inside templates/welcome folder. (In my case i am using swig as html.swig).