Accessing exports through require call when using coffeescript

I'm creating a node application using Coffeescript and have run into a syntactic question. Basically I have a simple file (foo.js) with an export that looks like this.

  foo = {}

  exports.foo = foo

Now, in a separate file, I want to create the equivalent syntax to this, but in Coffeescript.

  var bar = require('./foo').foo;

So that bar is automatically assigned to the variable foo in foo.js. However, I'm not sure what the proper Coffeescript to do this is. I've tried doing something like.

  bar = require './foo'.foo

But node yells at me, saying that it can't find the proper module. Given that, is there any way for me to achieve my desired result just using pure Coffeescript.

Sometimes you just need to use parens. The code you gave:

bar = require './foo'.foo

compiles to something that is clearly not what you want:

var bar;

bar = require('./foo'.foo);

You'll need to do something like

bar = require('./foo').foo

In the future, I would suggest using the in-browser CoffeeScript compiler at http://jashkenas.github.com/coffee-script/ to check that code is compiling as you expect.