Created
July 31, 2022 11:49
-
-
Save semlinker/060dcd42a7d9701c6fbc33eb07d3b62b to your computer and use it in GitHub Desktop.
HTTP Transfer Large Files
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
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