2012-08-16 67 views

回答

5

我按照linked question的指示操作。我使用node-xml2js庫以test fixture from the code base進行測試,並通過以下方式實現。

Meteor.startup(function() { 

    // This solves the issue 
    var require = __meteor_bootstrap__.require; 

    // The example from node-xml2js readme 
    var fs = require('fs'), 
     xml2js = require('xml2js'); 

    var parser = new xml2js.Parser(); 
    fs.readFile('/home/prashant/order.xml', 'utf8', function(err, data) { 
     parser.parseString(data, function (err, result) { 
      console.log(result); 
      console.log('Done'); 
     }); 
    }); 
}); 

我認爲,關鍵是要定義一個變量require並將其分配給流星的需要的功能。當Meteor加載服務器資產時,它也會加載require並解決傳遞依賴關係的問題。我沒有更改node-xml2js庫。

希望這會有所幫助!

+0

也看看這裏:http://stackoverflow.com/questions/10587964/where-do-we-put-node-modules-we-install-by-npm-in-a-meteor-project – Joscha 2012-08-29 06:31:39

3

在最新版本的流星(0.6.3,推測是起),你需要使用Npm.require()而不是require()本身。