I am working on an application and I have install mustache via npm.
Then in my main.js file I imported it like this:
const Mustache = require('mustache')
I then have a html template file with this:
<title></title>
in the tile part of the html file.
Using node I've then loaded the template file and tried to run render.
Here's the code:
fs.readFile('template.html', (err, data) => {
var mydata = Mustache.render(data, {title: "sometitle"});
fs.writeFile('result.html', mydata, (err) => {
if (err) throw err;
console.log('The file has been saved!');
});
});
I keep getting this error:
TypeError: Invalid template! Template should be a "string" but "object" was given as the first argument for mustache#render
How can I fix this so I can change and save the result?
via dj2017
No comments:
Post a Comment