2

I'm trying to understand Meteor as I create a project and I find some things a little difficult to understand so far.

1- When they say I can create a server and a client folder, where exactly I am meant to do so? Sibling of .meteor ? And will everything be at client's or server's scope when the app starts or do I have to do something else? If I create a foo.js and a foo function inside it in client folder, can I just call foo() in Meteor.isClient and it will work?

2- I need to create an upload folder so people can upload their stuff (images). So where am I supposed to do this? Plus, how can I get the absolute path to my project and find this upload folder inside?

During my attempts I tried the following:

fs = Meteor.npmRequire('fs');
__ROOT_APP_PATH__ = fs.realpathSync('.');

But __ROOT_APP_PATH__ is .meteor\local\build\programs\server. Quite hidden right?!

3- I saw some people uploading and saving files on MongoDB directly. This is something we usually don't do with relational databases. We move the file to a known folder on a CDN or on our own disk and save the hash or name of that file so we can easily find it. Isn't it encouraged with Meteor + MongoDB? Why would I save the file itself on Mongo instead of moving it to a folder?

Blakes Seven
  • 49,422
  • 14
  • 129
  • 135
Victor Ferreira
  • 6,151
  • 13
  • 64
  • 120

2 Answers2

3

not any specific way to do but meteor recommend it doing this way http://docs.meteor.com/#/basic/filestructure

atinder
  • 2,080
  • 13
  • 15
3

FOLDER STRUCTURE:

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

this is the basic folder structure for meteor project which i follow. For further reference or Documentation. For any question feel free ask in comments..

Community
  • 1
  • 1
iamhimadri
  • 532
  • 1
  • 5
  • 20
  • I created a folder called `lib`, inside it I put a JS file and declared `foo`. When I call it on `Meteor.isClient`, it says "foo is undefined" – Victor Ferreira Jul 22 '15 at 05:07
  • `lib` or `both` are similar and it the parent most directory..i mean sibling of `.meteor`..it is common code for meteor server and client. And i important thing it get executed before `client` and `server`. If you following folder structure and the code which you in client directory is taken as client code. So, no need to put use `Meteor.isClient` again. – iamhimadri Jul 22 '15 at 05:17
  • I mean I created `function foo(){}` inside `foo.js` in `/client` sibling of `.meteor` and called `foo()` on my main file, inside `Meteor.isClient` with the rest of the code. It says "foo is undefined" – Victor Ferreira Jul 22 '15 at 05:21
  • i am assuming your `function foo(){}` is a global function in another file and you calling it from other. i also sometime faced same issue on same. if you doing so put it in same file and check once...let us know. – iamhimadri Jul 22 '15 at 05:39
  • Meteor wrap all files in function expressions, anything declared in a file with `var` or like this `function name()` will be scoped to the file only. You must declare it globally so Meteor export it, see my answer there: http://stackoverflow.com/questions/31427322/file-load-order-in-meteor/31430986#31430986 – 255kb - Mockoon Jul 22 '15 at 05:47
  • You should export global variables via packaging - just create local package and add it into meteor project – dr.dimitru Jul 24 '15 at 15:44