Reputation: 34539
I'm using an API library in Node that doesn't return the status code of the HTTP response. However, it does return the response headers, which look like this:
{ ...
status: '200 OK',
... }
Is there any Node library I can use to parse the status code from the returned object's status? Will a crude +res.status.slice(0, 3)
do?
EDIT: Link to the library.
Upvotes: 0
Views: 977
Reputation: 99609
All HTTP status codes have 3 digits, so your slice example will work. However, I would personally just split on space:
var code = status.split(' ')[0];
Upvotes: 1