How to structure js-files


#1

Hi!
I’m new to Meteor, and I really like it! I’ve followed some tutorials and I’ve learnt a lot. But those tutorials write all the js-code in a single file.
Now I’m trying to build my first app, but I want to have a better file structure and separate the files from each other.

I now have a /client and a /server folder. My question is: Does all the js-files in the /client folder have to include

if (Meteor.isClient) { ... }

And the js-files in /server

if (Meteor.isServer) { ... }

#2

Nope, that’s the whole point of the client and server folders :- )


#3

Thanks! That’s what I thought. I think I need to follow more tutorials to get the hang of this :slight_smile:


#4

Yes, client and server directories separates natively what is execute – and visible – on the client and server respectively. Then I have /lib directory, which is normally where I put what you need to be visible on both sides. For all the rest I’m using the following approach:

  1. client/views is where I the templates – .html file – and template managers code –.js file. I usually create a subdirectory for for each template
  2. I put router.js, collections.js, resources.js in the /lib directory
  3. all the images in the /public/imgs dir
  4. publications.js, server methods and fixtures.js in the /server directory
  5. all your static assets that you need to load from the file system on the server into /private
  6. css files go in the /client/stylesheets

This approach is working for me, but except for what described here http://docs.meteor.com/#/full/structuringyourapp all the rest is part of your coding conventions.

Cheers,
Max


#5

Very good explanation, thank you!