2

We can the response code with:

res.status(v);

but later on for the same request, how can we check to see if it has been set? I am looking at the Express docs and not seeing how to do something like:

res.getStatus() // => 500
halfer
  • 19,824
  • 17
  • 99
  • 186
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

2 Answers2

5

res.statusCode is the answer and this is a core Node.js thing, it's not particular to Express.

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
  • not working for me. also tried res.statusCode(), not working either. it's also not mentioned in the express.js docs – mallocthePD Dec 26 '19 at 09:11
  • 1
    @mallocthePD Seems like `res.status(code)` might be what you're looking for [API Routes Response Helpers](https://nextjs.org/docs/api-routes/response-helpers) – yoyoyojoe Dec 19 '22 at 06:18
3

According to Aikon Mogwai you can use res.statusCode.

I tried it and it works!! (in express 4.16)

ErichBSchulz
  • 15,047
  • 5
  • 57
  • 61