PhantomJS NPM wrapAsync


Hello all, I have run in to some trouble trying to save the results from a PhantomJS script in to a Collection. I am running the PhantomJS script with the help of an NPM package, it’s actually very similar to the example found here

var phantomjs = Npm.require('phantomjs');
var spawn = Npm.require('child_process').spawn;

      runTest: function(options){
        command = spawn(phantomjs.path, ['assets/app/phantomDriver.js']);
        command.stdout.on('data',  function (data) {
        command.stderr.on('data', function (data) {
          console.log('stderr: ' + data);
        command.on('exit', function (code) {

I am unsure what needs to be wrapped inside a


call. Do I wrap both the phantomjs variable and the spawn variable? Or do I only wrap the function I am using in command.on(exit…) , saveToCollectionFunction(); ? I have tried several variations and I can’t seem to get it down. I have even tried Meteor.wrapAsync("runTest"); At any rate, the error I’m getting is -

throw new Error("Meteor code must always run within a Fiber. " + (STDERR) Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.