npm request moudule not giving the output

67 views Asked by At

Why when I run the npm request module the output I get is undefined?

const request = require('request');
request({
  url: 'https://maps.googleapis.com/maps/api/geocode/json?address=1301%20lombard%20street%20philadelphia',
  json: true
  }, (error, response, body) => {
     console.log(body);
});
2

There are 2 answers

0
sudo_shreyas On

I checked for proxy using env|grep -i proxy and then unset proxy for http_proxy or other proxies which is set.The command for that is:unset http_proxy

7
Teukros On

Seems like your code should work properly if request is installed. The possible reason why you get undefined is a problem with your internet connection.

Start with checking if you can access Internet at all. You can try this code:

 require('dns').resolve('www.google.com', function(err) { 
   if (err) { 
     console.log("No connection"); 
   } else { 
     console.log("Connected"); 
     } 
 });