我一直在使用sailsjs从外部网站请求json数据,然后将该数据发布到创建路由。当我第一次运行它时,它会工作约10-12次,然后应用程序将崩溃,并显示event.js throw er; connect ETIMEDOUT。
寻找更好的方法从https://cex.io/api/ticker/GHS/BTC请求json数据。
因此,我正在使用sailsjs,在文件config/bootstrap.js中添加了我的服务以运行。
寻找更好的方法从https://cex.io/api/ticker/GHS/BTC请求json数据。
因此,我正在使用sailsjs,在文件config/bootstrap.js中添加了我的服务以运行。
module.exports.bootstrap = function (cb) {
// My
tickerService.ticker();
// Runs the app
cb();
};
这是我的一次尝试~ 文件 api/services/tickerservice.js
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);
};
Cex.io图书馆Github https://github.com/matveyco/cex.io-api-node.js/blob/master/cexapi.js