Skip to content

Instantly share code, notes, and snippets.

@firasdib

firasdib/body.js Secret

Created May 15, 2019 13:47
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 firasdib/73a2415ac91ba102850c5750f5ab1558 to your computer and use it in GitHub Desktop.
Save firasdib/73a2415ac91ba102850c5750f5ab1558 to your computer and use it in GitHub Desktop.
module.exports = function getBody(request) {
return new Promise((resolve, reject) => {
let body = '';
request.on('data', chunk => {
body += chunk.toString();
});
request.on('end', () => {
try {
resolve(JSON.parse(body));
} catch (error) {
reject(error);
}
});
request.on('error', error => {
reject(error);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment