Hacker News new | ask | show | jobs
by AndyKelley 4251 days ago
I see this in example code:

    if (Meteor.isClient) {
I don't get it. Are we shipping server side code to the client?
2 comments

Not unless you want to. Anything in a `server/` or `private/` directory is not sent to the client. This pattern is sometimes used to group similar functions in a single file.

Relevant section of the docs: https://docs.meteor.com/#/basic/filestructure

If you use browserify for your "isomorphic" code (i.e. JS that runs on client and server), you may have situations in which you need to run different code depending on whether the code executes on the client and server (think XMLHttpRequest vs `require('http')`).

In node you do that by extracting the code in a separate module and telling browserify to use the browser-specific module via your package.json.

In Meteor you can just check whether you're running in the client or server at runtime and execute different code accordingly. That's what `Meteor.isClient` is for.