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

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

问题描述

我有一个使用节点 twit 模块的应用程序,该模块可通过

获得

npm install twit

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

所以,它在.meteor/local/build/server/node_modules/twit

我尝试在项目根目录下安装它,但该项目没有找到该模块.这让我找到了上述可行的解决方案.

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

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

meteor deploy [appname] --password

应用程序部署成功.

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

[Mon May 07 2012 01:59:53 GMT+0000 (UTC)] 警告node.js:201扔e;//process.nextTick 错误,或第一个滴答时的 'error' 事件^错误:找不到模块twit"在 Function._resolveFilename (module.js:332:11)在 Function._load (module.js:279:25)在 Module.require (module.js:354:17)在要求 (module.js:370:17)在应用程序/服务器/server.js:2:12在/meteor/containers/84162a7c-24e8-bf26-6fd8-e4ec13b2a935/bundle/server/server.js:111:21在 Array.forEach(本机)在函数<匿名>(/meteor/containers/84162a7c-24e8-bf26-6fd8-e4ec13b2a935/bundle/server/underscore.js:76:11)在/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 ->等待[Mon May 07 2012 01:59:53 GMT+0000 (UTC)] 错误应用程序崩溃,代码:1[2012 年 5 月 7 日星期一 02:29:55 GMT+0000 (UTC)] INFO HIT/24.94.158.145[2012 年 5 月 7 日星期一 02:29:59 GMT+0000 (UTC)] INFO HIT/favicon.ico 24.94.158.145[2012 年 5 月 7 日星期一 02:30:46 GMT+0000 (UTC)] INFO HIT/24.94.158.145[2012 年 5 月 7 日星期一 02:30:50 GMT+0000 (UTC)] INFO HIT/favicon.ico 24.94.158.145

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

解决方案

最后,我是这样写的.它适用于本地和流星服务器.谢谢伊恩 :D

在app/public"中安装 npm 模块:

<前>app/public# npm install MODULE_NAME

在 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');});

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

npm install twit

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

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.

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.

When I deploy to meteor.com through the command

meteor deploy [appname] --password

The application deploys successfully.

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?

解决方案

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

install npm module inside "app/public":

    app/public# npm install MODULE_NAME

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天全站免登陆