Shared code between server & client

Hi everyone,

I’m trying to write my own app using meteor but I have a question. In every app we have some codes that should be run in client side and some other that should be run in server side. Now in meteor we also have some codes that should be run on both like defining a new collection object.

I was wondering to write the codes that need to be run in both env. twice instead of importing the common parts in each file. Is it wrong ? I know that means having duplicate codes but I want to make sure that nothing wrong in term of performance and security happens. So defining a collection twice like this :

/server /main.js:
ABC = new Mongo.Collection("abcCollection");

/client/main.js:
ABC = new Mongo.Collection("abcCollection");

Will such act behave just like importing the file in client side ? I ask it because I want to make sure that the only thing that is happening by importing a js file in meteor is just like putting the code in that place (I know that may sound stupid but just want to make sure).

No, the code will run in both sides (client and server) which is fine.

1 Like

With the new meteor default folder structure how do we write code once to execute on client and server?