I'm using Meteor.require('npmPackage')
to use a NPM package. However I seem to be getting an error when writing to mongo in npm package's callback function.
Error:
Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
Code
npmPackage.getInfo(function(err, data) {
UserSession.insert({
key: 'info',
value: data
});
console.log(data);
});
I tried wrapping the code within Fiber but the same error message is still shown:
Fiber(function() {
npmPackage.getInfo(function(err, data) {
UserSession.insert({
key: 'info',
value: data
});
console.log(data);
});
}).run();
Question: How should Meteor.bindEnvironment
be used to get this to work?