如何在meteor.com的Meteor应用程序中部署节点模块? [英] How can I deploy node modules in a Meteor app on meteor.com?

查看:84
本文介绍了如何在meteor.com的Meteor应用程序中部署节点模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,该应用程序使用通过

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

npm install twit

我从本地部署了节点模块 .meteor/local/build/server/

I deployed the node module locally from .meteor/local/build/server/

因此,它在以下位置可见 .meteor/local/build/server/node_modules/twit

So, it is visible at .meteor/local/build/server/node_modules/twit

我尝试将其安装在项目根目录下,但项目未找到该模块.这使我想到了上面可行的解决方案.

I tried installing it at project root but the project did not find the module. Which led me to the above solution which works.

我的应用程序现在在本地运行良好.我能够运行并执行所有操作,并且可以根据自己想做的事情从我的Meteor服务器端或客户端与Twitter进行交互.没有崩溃.

My application now runs fine locally. I am able to run and do everything and can interact with Twitter from my Meteor server side or client side depending on what I want to do. No crashes.

当我通过命令部署到meteor.com时

When I deploy to meteor.com through the command

meteor deploy [appname] --password

应用程序成功部署.

当我尝试从浏览器访问(anonistream.meteor.com上的应用程序)[anonistream.meteor.com]时,它失败,并且日志中包含此错误.

When I attempt to access the (app at anonistream.meteor.com)[anonistream.meteor.com] from a browser it fails and the logs contain this error.

[Mon May 07 2012 01:59:53 GMT+0000 (UTC)] WARNING
node.js:201
   throw e; // process.nextTick error, or 'error' event on first tick
         ^
Error: Cannot find module 'twit'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at app/server/server.js:2:12
at /meteor/containers/84162a7c-24e8-bf26-6fd8-e4ec13b2a935/bundle/server/server.js:111:21
at Array.forEach (native)
at Function.<anonymous>
 (/meteor/containers/84162a7c-24e8-bf26-6fd8-     e4ec13b2a935/bundle/server/underscore.js:76:11)
at /meteor/containers/84162a7c-24e8-bf26-6fd8-e4ec13b2a935/bundle/server/server.js:97:7
[Mon May 07 2012 01:59:53 GMT+0000 (UTC)] INFO STATUS running -> waiting
[Mon May 07 2012 01:59:53 GMT+0000 (UTC)] ERROR Application crashed with code: 1
[Mon May 07 2012 02:29:55 GMT+0000 (UTC)] INFO HIT / 24.94.158.145
[Mon May 07 2012 02:29:59 GMT+0000 (UTC)] INFO HIT /favicon.ico 24.94.158.145
[Mon May 07 2012 02:30:46 GMT+0000 (UTC)] INFO HIT / 24.94.158.145
[Mon May 07 2012 02:30:50 GMT+0000 (UTC)] INFO HIT /favicon.ico 24.94.158.145

有人对如何实现这一目标有任何建议吗?

Does anyone have any suggestions on how this might be accomplished?

推荐答案

最后,我这样写. 它既可以在本地也可以在流星服务器上使用.伊恩:D

finally, I wrote like this. it works both in local and meteor sever. thx Ian :D

在应用程序/公共"中安装npm模块:

install npm module inside "app/public":


    app/public# npm install MODULE_NAME

在app/server/server.js内部:

inside app/server/server.js:

Meteor.startup(function () {
    var require = __meteor_bootstrap__.require;
    var path = require('path');
    var base = path.resolve('.');
    var isBundle = path.existsSync(base + '/bundle');
    var modulePath = base + (isBundle ? '/bundle/static' : '/public') + '/node_modules';

    var MODULE_NAME = require(modulePath + '/MODULE_NAME');
});

这篇关于如何在meteor.com的Meteor应用程序中部署节点模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆