2015-07-22 123 views
2

我想了解流星,因为我创建了一个项目,并且发现了一些迄今为止难以理解的事情。如何组织Meteor项目中的文件夹和文件?

1-当他们说我可以创建一个server和一个client文件夹时,我确切的意思是这么做的? .meteor的兄弟?当应用程序启动时,一切都会在客户端或服务器的范围内,还是必须做其他事情?如果我在client文件夹中创建一个foo.jsfoo函数,我可以在Meteor.isClient中调用foo(),它会工作吗?

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上而不是将其移动到文件夹中?

回答

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 

这是我跟着流星项目的基本文件夹结构。进一步referenceDocumentation。对于任何问题,请随时询问我的意见..

+0

我创建了一个名为'lib'的文件夹,里面放了一个JS文件并声明了'foo'。当我在Meteor.isClient上调用它时,它说“foo是未定义的” –

+0

'''lib'或'both'是相似的,它是父目录最多的目录..我是'.meteor'的同级..它是通用代码流星服务器和客户端。我重要的是它在'client'和'server'之前执行。如果您遵循文件夹结构并将您在客户端目录中的代码视为客户端代码。所以,不需要再次使用'Meteor.isClient'。 – iamhimadri

+0

我的意思是我在'.meteor'的'/ client'兄弟中的'foo.js'内创建了'function foo(){}',并在'Meteor.isClient'内的main文件中调用了'foo()'其余的代码。它说“foo是未定义的” –

相关问题