Skip to content

Instantly share code, notes, and snippets.

@qoomon
Created October 25, 2022 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qoomon/884739e01885c1c4c0ce430caf1cc241 to your computer and use it in GitHub Desktop.
Save qoomon/884739e01885c1c4c0ce430caf1cc241 to your computer and use it in GitHub Desktop.
Parse http.IncomingMessage body
async function parseBody(res) {
return new Promise((resolve, reject) => {
let body = '';
res.on('data', (chunk) => body += chunk);
res.on('end', () => resolve(body));
}).then(body => res.body = body ? JSON.parse(body) : undefined);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment