Created
October 31, 2018 10:58
-
-
Save ufocoder/1d7927cc638ae88a01a0159a1b8f3246 to your computer and use it in GitHub Desktop.
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
| router.get("/some-file", function (req, res) { | |
| const url = "./data/some-file.ext"; | |
| function handleError (err) { | |
| res.writeHead(404); | |
| res.end(); | |
| } | |
| function handleSuccess (file) { | |
| res.writeHead(200, { "Content-Type": "application/octet-stream" }); | |
| res.write(file); | |
| res.end(); | |
| } | |
| readFile(url, function (err, file) { | |
| if (err) { | |
| handleError(err); | |
| } else { | |
| handleSuccess(file); | |
| } | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment