Skip to content

Instantly share code, notes, and snippets.

@sang4lv
Last active December 17, 2015 17:49
Show Gist options
  • Save sang4lv/5648943 to your computer and use it in GitHub Desktop.
Save sang4lv/5648943 to your computer and use it in GitHub Desktop.
Node File Write
//Which is the better way? Perform FS read during response.write or independently?
//Read during response write
response.write(function() {
fs.readFile('./index.html', function (error, html) {
if (error) {
throw error;
} else {
return html;
}
});
});
//Read then write response
fs.readFile('./index.html', function (error, html) {
if (error) {
throw error;
} else {
response.write(html);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment