Skip to content

Instantly share code, notes, and snippets.

@tameemsafi
Created December 4, 2017 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tameemsafi/87de0df12d74bb7bbbebd82ca5fa2a2f to your computer and use it in GitHub Desktop.
Save tameemsafi/87de0df12d74bb7bbbebd82ca5fa2a2f to your computer and use it in GitHub Desktop.
Generate html output before rendering response with expressjs
function(err, html) {
let outputFolder = path.resolve('output');
// Check if folder does not exist
if ( !fs.existsSync(outputFolder) ) {
// Create folder
fs.mkdirSync(outputFolder);
}
// Write html output to file
fs.writeFileSync(path.join(outputFolder, 'output.html'), html);
// Send html with response
res.send(html);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment