我正在尝试了解Meteor,因为我创建了一个项目,到目前为止我发现有些事情有点难以理解。
1-当他们说我可以创建一个server
和一个client
文件夹时,我究竟打算这样做? .meteor
的同级?当应用程序启动或我必须做其他事情时,一切都将在客户端或服务器范围内吗?如果我在foo.js
文件夹中在其中创建了foo
和client
功能,我是否可以在foo()
中拨打Meteor.isClient
它是否有效?
2-我需要创建一个上传文件夹,以便人们可以上传他们的东西(图像)。那么我应该在哪里这样做?另外,我如何获得项目的绝对路径并在里面找到这个upload
文件夹?
在我尝试期间,我尝试了以下内容:
fs = Meteor.npmRequire('fs');
__ROOT_APP_PATH__ = fs.realpathSync('.');
但__ROOT_APP_PATH__
是.meteor\local\build\programs\server
。相当隐藏吧?!
3-我看到有些人直接在MongoDB上传和保存文件。这是我们通常不对关系数据库做的事情。我们将文件移动到CDN或我们自己的磁盘上的已知文件夹,并保存该文件的哈希或名称,以便我们可以轻松找到它。 Meteor + MongoDB不鼓励它吗?为什么我要将文件本身保存在Mongo而不是将其移动到文件夹?
答案 0 :(得分:3)
没有任何具体的方法,但流星建议这样做 http://docs.meteor.com/#/basic/filestructure
答案 1 :(得分:3)
文件夹结构:
both/ (OR lib/) -- common code for server and client
|- collections/ -- declare collections (e.g Employer = new Meteor.Collection("employer");)
|- router / -- router code(e.g Router.route(..))
client/ -- client side code
|- global/ -- all global variable for client
|- helpers/ -- global helper for client (for all templates)
|- plugins/ -- all the plugins code(if you use any)
|- stylesheets/ -- css / less files
|- templates/ -- all templates
|- home.html -- home template(html)
|- home.js -- home template(js)
public/ -- images/icons/fonts (meteor looking at this file)
server/ -- server code
|- methods/ -- server methods/API (e.g Meteor.methods({...}))
|- publish/ -- publish code from server
这是我遵循的流星项目的基本文件夹结构。进一步reference或Documentation。对于任何问题,请在评论中随意询问..