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

后端 未结 7 1480
轻奢々
轻奢々 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:39

    Answer found from JonathanKingston on meteor irc. Referred to meteoric project

    Put node modules in the projects public directory.

    Use code like this to make sure it loads.

    var require = __meteor_bootstrap__.require;
    var path = require("path");
    var fs = require('fs');
    var Twit;
    var twitPath = 'node_modules/twit';
    
    var base = path.resolve('.');
    if (base == '/'){
      base = path.dirname(global.require.main.filename);   
    }
    
    var publicPath = path.resolve(base+'/public/'+twitPath);
    var staticPath = path.resolve(base+'/static/'+twitPath);
    
    if (path.existsSync(publicPath)){
      Twit = require(publicPath);
    }
    else if (path.existsSync(staticPath)){
      Twit = require(staticPath);
    }
    else{
      console.log('node_modules not found');
    }
    

    meteor deploy should work find after that, sill me for putting my node modules in the server dirs

    0 讨论(0)
提交回复
热议问题