aboutsummaryrefslogtreecommitdiff
path: root/bench/stream-file-upload-client/stream-file-node.mjs
blob: 9a09572858b19cecc9524b2ed0fb45829b8c3fe1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { createReadStream } from "node:fs";
import http from "node:http";

console.time("stream-file-node");
createReadStream(process.env.FILE ?? "hello.txt")
  .pipe(
    http
      .request(process.env.URL ?? "http://localhost:3000", {
        method: "POST",
      })
      .on("response", response => {
        response.on("data", data => {
          console.log("Sent", parseInt(data.toString(), 10), "bytes");
        });
      }),
  )
  .on("close", () => {
    console.timeEnd("stream-file-node");
  });