I am trying to minify html file using the node module html-minifier. In order to this I have created this little node.js file which should be able to do this
'use strict'
var fs = require('fs');
var minifier = require('html-minifier').minify;
var htmlFile = fs.readFileSync("users/email/test.html");
var output = minifier(htmlFile, {
removeAttributeQuotes: true
});
process.stdout.write(output);
but when I run the program I get the following error.
TypeError: value.replace is not a function
Any idea why this is happening. I am using version 4.0.0 of html-minifier
Since you haven't specified a text encoding, readFileSync
returned a Buffer
, not a string. See the readFileSync
documentation.
If you know the encoding to use, you can specify it as a second argument:
var htmlFile = fs.readFileSync("users/email/test.html", "utf8");