Nodejs Request Promise How to display status code Nodejs Request Promise How to display status code express express

Nodejs Request Promise How to display status code


According to the documentation we need to define in the options that we want to return the full response.

https://github.com/request/request-promise#get-the-full-response-instead-of-just-the-body

const options = {        resolveWithFullResponse: true}


I think res object might undefined. you can try request as callback

request(options, function (error, response, body) {  console.log('statusCode:', response && response.statusCode); });

or you can do like this https://www.npmjs.com/package/request-promise

var options = {    uri: 'http://the-server.com/will-return/404',    simple: true,    transform: function (body, response, resolveWithFullResponse) { /* ... */ }};rp(options)    .catch(errors.StatusCodeError, function (reason) {        // reason.response is the transformed response    });