main.js - Server
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { CurrentWeather } from '../collections/currentWeatherCollection.js';
import ForecastIo from 'forecastio';
if (Meteor.isServer) {
var forecastIo = new ForecastIo('c997a6d0090fb4f6ee44cece98e9cfcc');
forecastIo.forecast('30.533', '-87.213').then(function(data) {
const currentWeather = JSON.stringify(data.currently, null, 2);
CurrentWeather.insert({currentWeather: currentWeather});
});
}
我知道我必须在Meteor.bindEnvironment()中包装回调,但是我不知道如何用这个承诺做到这一点?任何帮助将不胜感激 .
1 回答
我通常会使用期货 . 例如