0

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.

James Ko
  • 32,215
  • 30
  • 128
  • 239

1 Answers1

1

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];
Evert
  • 93,428
  • 18
  • 118
  • 189