title: What is the best way to retrieve JSON from URL in Node.js
body: <p>So I've been using sailsjs to request json data from an external website and then posting that data to the create route. When I first run it, it will work for around 10-12 times and then the application will crash with event.js throw er; connect ETIMEDOUT</p>
  
  <p>Looking for a better way to request json data from <a href="https://cex.io/api/ticker/GHS/BTC" rel="nofollow">https://cex.io/api/ticker/GHS/BTC</a>.</p>
  
  <p>So I'm using sailsjs and in the file config/bootstrap.js I've added my service to run.</p>
  
  <pre><code>module.exports.bootstrap = function (cb) {
  
      // My
      tickerService.ticker();
  
      // Runs the app
      cb();
  };
  </code></pre>
  
  <p>This is one of my attempts~ file api/services/tickerservice.js</p>
  
  <pre><code>function storeTicker(){
      console.log('Running!');
  
      //retrieves info from https://cex.io/api/ticker/GHS/BTC
      require("cexapi").ticker('GHS/BTC', function(param){
  
          console.log(param);
  
          Tickerchart.create( param, function tickerchartCreated (err, tickerchart) {});
  
      });
  } 
  
  module.exports.ticker = function(){
  
      setInterval(storeTicker, 6000);
  
  };
  </code></pre>
  
  <p>Cex.io Library Github
  <a href="https://github.com/matveyco/cex.io-api-node.js/blob/master/cexapi.js" rel="nofollow">https://github.com/matveyco/cex.io-api-node.js/blob/master/cexapi.js</a></p>