Skip to content

Instantly share code, notes, and snippets.

@gocs
Created April 8, 2023 15:40
Show Gist options
  • Save gocs/a8fb78ea98906978e2e7ddbf07f28a02 to your computer and use it in GitHub Desktop.
Save gocs/a8fb78ea98906978e2e7ddbf07f28a02 to your computer and use it in GitHub Desktop.
async readbody of a http request
function readBody(req) {
return new Promise((resolve, reject) => {
let body = "";
req.on("data", (chunk) => { body += "" + chunk; });
req.on("end", () => { resolve(body); });
req.on("error", (err) => { reject(err); });
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment