I'm using res.send
and no matter what, it returns status of 200. I want to set that status to different numbers for different responses (Error, etc)
This is using express
I'm using res.send
and no matter what, it returns status of 200. I want to set that status to different numbers for different responses (Error, etc)
This is using express
For adding response headers before send, you can use the setHeader method:
The status only by the status method:
Both at the same time with the writeHead method:
http://nodejs.org/docs/v0.4.12/api/http.html#response.writeHead
Since the question also mentions Express you could also do it this way using middleware.
You should use setHeader method and status method for your purpose.
SOLUTION:
set statusCode var before send() call
I'll assume that you're using a library like "Express", since nodejs doesn't provide a
res.send
method.As in the Express guide, you can pass in a second optional argument to send the response status, such as: