Correct way to determine where I am running?

All over the mojito code base, I see the following pattern in common affinity code:

   if (this._adapter.req) { 
      // server code
  } else {
      // client code

Is this the best way to determine whether I have nodejs available to me or not in my common code?

2 Replies
  • @Ronald, what version of mojito are you using? I don't see any this._adapter.req in the current source code.

    About your question, I usually recommend two things to avoid forking your logic:

    • Refactor the code so the same code works in server and client (usually by using the common APIs provided by mojito and YUI).
    • Split the code into a server affinity and client affinity, which helps if you need to "require(something)".
  • Thanks Caridy, You're quite right! Thank you for the guideline. It means some more refactoring, but it will be worthwhile in the end.

    BTW. Mojito helps produce maintainable code!

    We are still stuck on, next we'll migrate onto 0.5.5. there are some tickets of ours in there.

    Best, Ron


Recent Posts

in Yahoo! Mojito