I use fs
to read the file which is in .md format and I want to transform it into html file.
This is my code so far:
fs = require('fs');
fs.readFile(__dirname + '/posts/react-v16.13.0.md', 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
console.log(data);
});
the file is situated in that folder and has that name.
This function puts in console the content of the .md file.
For converting it to html I added this:
const showdown = require('showdown');
converter = new showdown.Converter();
...
fs = require('fs');
fs.readFile(__dirname + '/posts/react-v16.13.0.md', 'utf8', function (
err,
data
) {
if (err) {
return console.log(err);
}
text = data;
html = converter.makeHtml(text);
console.log(html);
});
It puts the file as html in the log which is fine.
My problem is how to do this if there are multiple files in /posts/
folder, how to read and send those files?
I would like to send them to front-end using a POST method.
Is it possible to read all the files from the folder, transform them and send them?
from Read all .md files, convert them to html and send them
No comments:
Post a Comment