Ejs error 'include' requires "filename" option
PROBLEM
in some online examples you can use syntax like this
<%- include hello-world %>
or even you can use
<%- include('hello-world'); %>
you may get an error that includes missing filename
Exception occurred: Error: `include` requires the 'filename' option.
Q where is the problem if my syntax is correct?
+3
source to share
1 answer
Decision
the simple answer is "file path"
but even if you used the correct path, you will also get the error
var fs = require('fs');
ejs.render(fs.readFileSync(__dirname + '/templates/include.ejs', 'utf8'), {});
Correct answer: "use renderFile"
ejs.renderFile(__dirname + '/templates/include.ejs', {}, function(err, result) {
if (!err) {
res.end(result);
}
else {
res.end(err.toString());
console.log(err);
}
});
REF
+4
source to share