Created
December 4, 2017 12:49
-
-
Save tameemsafi/87de0df12d74bb7bbbebd82ca5fa2a2f to your computer and use it in GitHub Desktop.
Generate html output before rendering response with expressjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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