Last active
December 17, 2015 17:49
-
-
Save sang4lv/5648943 to your computer and use it in GitHub Desktop.
Node File Write
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
| //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