I’ve been trying a couple of hours to make this work, but i just cant figure it out.
I’m fetching some json data with request, looping through it and trying to insert into the db. I’ve removed a bunch of code to make it cleaner for you. Don’t worry about that!
Error:
Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
I’ve tried to implement Meteor.bindEnvironment, Meteor.wrapAsync & Fibers.
But i’m doing something wrong, can someone help me out here?
main.js
import { Meteor } from 'meteor/meteor'
import '../imports/api/games.js'
import { Games } from '../imports/api/games.js'
const request = require('request-promise')
request(url).then(res => {
res = JSON.parse(res)
for(i in res){
const game = res[i]
Games.insert({
name: game.name,
date: new Date()
})
}
})
Meteor.startup(() => {
})
I looked through your guide before posting this thread, even though the title sounds perfect “Using Promises and async/await in Meteor”. It didn’t help me. Perhaps i’ll have to give it more time. This is the fifth time i’m rage-quitting meteor because so many simple things like this just turns out to be so hard.