So, I use sailsjs to request json data from an external website and put that data in the creation path. When I first launch it, it will work about 10-12 times, and then the application will crash using event.js throw er; connect ETIMEDOUT
Looking for the best way to request json data from https://cex.io/api/ticker/GHS/BTC .
So, I use sailsjs in the config / bootstrap.js file as well. I added my service to run.
module.exports.bootstrap = function (cb) {
tickerService.ticker();
cb();
};
This is one of my attempts ~ file api / services / tickerservice.js
function storeTicker(){
console.log('Running!');
require("cexapi").ticker('GHS/BTC', function(param){
console.log(param);
Tickerchart.create( param, function tickerchartCreated (err, tickerchart) {});
});
}
module.exports.ticker = function(){
setInterval(storeTicker, 6000);
};
Cex.io Github library
https://github.com/matveyco/cex.io-api-node.js/blob/master/cexapi.js