我按照 github meteorirc 项目的领导把它们放在/public/
我通过 npm 从/public/中安装了我的节点模块,因此我有一个/public/node_modules/目录。
我不认为这对他们来说是“合适”或“标准”的地方,因为根据 Meteor 文档...
Meteor gathers all your JavaScript files, excluding anything under the client and public subdirectories, and loads them into a Node.js server instance inside a fiber
要加载的代码在服务器目录和服务器 js 文件中,如下所示。
var require = __meteor_bootstrap__.require;
var path = require("path");
var fs = require('fs');
var base = path.resolve('.');
if (base == '/'){
base = path.dirname(global.require.main.filename);
}
var Twit;
var twitPath = 'node_modules/twit';
var publicTwitPath = path.resolve(base+'/public/'+twitPath);
var staticTwitPath = path.resolve(base+'/static/'+twitPath);
if (path.existsSync(publicTwitPath)){
Twit = require(publicTwitPath);
}
else if (path.existsSync(staticTwitPath)){
Twit = require(staticTwitPath);
}
else{
console.log('WARNING Twit not loaded. Node_modules not found');
}
根据文档,这不是标准的,我认为我不应该这样做。然而,它既适用于我的开发平台,也适用于 deploy meteor.com 的生产平台。
节点模块应该安装在项目的目录结构中的什么位置,以便它们在本地工作以及部署在 meteor.com 或其他地方时?
最佳答案
cd /usr/local/meteor/lib/ && npm install <module>
关于javascript - 我们将通过 npm 安装的节点模块放在 Meteor 项目中的什么位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10587964/