Reputation: 1891
I know the Meteor file structure is a bit ambiguous, but at this point some conventions has formed and I was wondering where people usually put the code that runs on both server and client. I would like to keep it in a separate folder/file to make the project folder more manageable. I have a client folder for client-side code, a server folder for server-side, and a public folder for public files. But I'm unsure what the conventions say about the shared code that runs on both the client and the server, like declaring collections, etc.
Thanks!
Upvotes: 1
Views: 725
Reputation: 2666
From the docs,
All JavaScript files outside special directories are loaded on both the client and the server. That's the place for model definitions and other functions. Meteor provides the variables Meteor.isClient and Meteor.isServer so that your code can alter its behavior depending on whether it's running on the client or the server.
Also from the section on File Load Order,
There are several load ordering rules. They are applied sequentially to all applicable files in the application, in the priority given below:
- HTML template files are always loaded before everything else
- Files beginning with main. are loaded last
- Files inside any lib/ directory are loaded next
- Files with deeper paths are loaded next
- Files are then loaded in alphabetical order of the entire path
This suggests that the best practice would be to place the files in the lib/
directory.
Upvotes: 2