I have a fairly simply web app that uses expressjs
and handlebarsjs
to retrieve and format markdown files and render them as html to the browser. I'd like to write the html output to the disk instead of sending it to the browser ? I know there are static website generators out there, but I'd rather just modify the existing program a tiny bit instead of installing a whole new kitchen sink.
Asked
Active
Viewed 59 times
0

punkish
- 13,598
- 26
- 66
- 101
1 Answers
0
The standard filesystem library should be able to do this -
fs.writeFile(filename, html, function (err) {
if (err) throw err;
console.log('It\'s saved!');
});
Where filename is the filename, and html is the content you want to write to the file.
See the filesystem docs.

Ash
- 6,483
- 7
- 29
- 37
-
thanks, but that is not what I am looking for. How do I generate the *html* in the first place? With `expressjs` I do `app.render('template', data)` but that sends the html to the browser. I want *that* html to be written to a file. – punkish Nov 29 '15 at 04:11
-
How you generate the html will be up to you - but the example shows how you'd write the html to a file. If you want to keep using express and handlebars to generate the html you could send a request to a 'live' page and then save the response body to a file. If this is what you're after I can update my answer with a new code sample. – Ash Nov 30 '15 at 06:46