node.js - Get request's first response status code -


i requesting example.com redirects me www.example.com 301 or 302 status , response www.example.com code 200. want statuses not last. use 'request' module in node server. here code

 app.post("/check", function(req, res) {   var link = req.body.url;    var opts = {     uri: link,     gzip: true,     followredirect :function (resp) {       return true;     }   };   request(opts, function (error, res, body) {     if (res.statuscode > 300 && res.statuscode < 400 && res.headers.location) {       if (url.parse(res.headers.location).hostname) {       } else {       }     } 

not sure want output try this:

app.post("/check", function(req, res) {   var link = req.body.url;   var redirectcodes = [];    var opts = {     uri: link,     gzip: true,     followredirect :function (resp) {       redirectcodes.push(resp.statuscode);       return true;     }   };   request(opts, function (error, res, body) {     res.end(json.stringify({       body: body,       redirectcodes: redirectcodes     }, null, 2));   } }); 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -