-
-
Save firasdib/73a2415ac91ba102850c5750f5ab1558 to your computer and use it in GitHub Desktop.
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
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