Skip to content

Instantly share code, notes, and snippets.

@ufocoder
Created October 31, 2018 10:51
Show Gist options
  • Select an option

  • Save ufocoder/30ee6c335b4d4e2debce3f2fe57a3b81 to your computer and use it in GitHub Desktop.

Select an option

Save ufocoder/30ee6c335b4d4e2debce3f2fe57a3b81 to your computer and use it in GitHub Desktop.
import { readFile } from "fs";
router.get("/some-file", function (req, res) {
const url = "./data/some-file.ext";
readFile(url, function (err, file) {
if (err) {
res.writeHead(404);
res.end();
} else {
res.writeHead(200, { "Content-Type": "application/octet-stream" });
res.write(file);
res.end();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment