Skip to content

Instantly share code, notes, and snippets.

@kyriesent
Created November 20, 2014 16:52
Show Gist options
  • Save kyriesent/cbe413d2a1323334aac1 to your computer and use it in GitHub Desktop.
Save kyriesent/cbe413d2a1323334aac1 to your computer and use it in GitHub Desktop.
Using Proxy Module instead of Globals
# .. Start express app
app = createExpressApp()
require('./routes') app
common = module.exports
common.models = require './models'
common.controllers = require './controllers'
module.exports =
students: require './students.controller'
module.exports =
Student: require './student'
common = require '../common'
module.exports = (webapp) ->
app.get '/student/:_id', ->
common.controllers.students.view req.params._id
common = require '../common' # this will replace using global.models and keep our dependencies clear
module.exports =
view: ->
# ... do stuff
return common.models.Student.view

By using a common module (we can name it whatever we want), we make dependencies explicit, reduce unnecessary documentation, and avoid polluting the global namespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment