Skip to content

Instantly share code, notes, and snippets.

@semlinker
Created July 31, 2022 11:49
Show Gist options
  • Save semlinker/060dcd42a7d9701c6fbc33eb07d3b62b to your computer and use it in GitHub Desktop.
Save semlinker/060dcd42a7d9701c6fbc33eb07d3b62b to your computer and use it in GitHub Desktop.
HTTP Transfer Large Files
const fs = require("fs");
const http = require("http");
const util = require("util");
const readFile = util.promisify(fs.readFile);
const server = http.createServer(async (req, res) => {
res.writeHead(200, {
"Content-Type": "text/plain;charset=utf-8",
});
const buffer = await readFile(__dirname + "/big-file.txt");
res.write(buffer);
res.end();
});
server.listen(3000, () => {
console.log("app starting at port 3000");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment