Created
October 25, 2022 14:38
-
-
Save qoomon/884739e01885c1c4c0ce430caf1cc241 to your computer and use it in GitHub Desktop.
Parse http.IncomingMessage body
This file contains 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
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