How can I deploy node modules in a Meteor app on meteor.com?

后端 未结 7 1599
轻奢々
轻奢々 2020-11-29 02:16

I have an application that uses the node twit module that is available via

npm install twit

I deployed the node module locally from .m

7条回答
  •  被撕碎了的回忆
    2020-11-29 02:37

    As of Meteor 6.0, now we need to use Npm.require() instead. Additionally, we need to declare the module as global variables, since Meteor now has file-level scope.

      var path = Npm.require('path');
      var fs = Npm.require('fs');
      var base = path.resolve('.');
      var isBundle = fs.existsSync(base + '/bundle');
      var modulePath = base + (isBundle ? '/bundle/static' : '/public') + '/node_modules';
      MODULE_NAME = Npm.require(modulePath + '/MODULE_NAME'); // NOTE, this is going to be a global variable
    

提交回复
热议问题