Skip to content

Instantly share code, notes, and snippets.

@fbn4sc
Created January 26, 2018 01:16
Show Gist options
  • Save fbn4sc/8117de785a193346728bf1e4ad164773 to your computer and use it in GitHub Desktop.
Save fbn4sc/8117de785a193346728bf1e4ad164773 to your computer and use it in GitHub Desktop.
Stream the contents of a file via http
const http = require("http");
const fs = require("fs");
const server = http.createServer((req, res) => {
fs
.createReadStream(process.argv[3])
.on("data", data => res.write(data))
.on("end", () => res.end());
});
server.listen(process.argv[2]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment