There are a few ways to write a module in Coffee Script for Node. Below are two ways to contrast their usages. Notice how they share data @url and use function @find.
1.
user.coffee
-------------
class User
constructor: (url) ->
@url = url
findOrCreate: (user, callback) ->
@find user.username, (err, res) ->
...
find: (username, callback) ->
...
module.exports.User = User
example.coffee
-------------
user = require('user')
User = new user.User('url')
...
User.findOrCreate u, (err, res) ->
console.log @url
...
-------------
class User
constructor: (url) ->
@url = url
findOrCreate: (user, callback) ->
@find user.username, (err, res) ->
...
find: (username, callback) ->
...
module.exports.User = User
example.coffee
-------------
user = require('user')
User = new user.User('url')
...
User.findOrCreate u, (err, res) ->
console.log @url
...
2.
user.coffee
-------------
init = (url) ->
@url = url
find = (username, callback) ->
...
findOrCreate = (user, callback) ->
console.log @url
@find user.username, (err, res) ->
...
module.exports =
init: init
findOrCreate: findOrCreate
example.coffee
---------------
user = require 'user'
user.init 'url'
...
user.findOrCreate u, (err, res) ->
...
-------------
init = (url) ->
@url = url
find = (username, callback) ->
...
findOrCreate = (user, callback) ->
console.log @url
@find user.username, (err, res) ->
...
module.exports =
init: init
findOrCreate: findOrCreate
example.coffee
---------------
user = require 'user'
user.init 'url'
...
user.findOrCreate u, (err, res) ->
...