Skip to content

Instantly share code, notes, and snippets.

@theycallmeswift
Created January 3, 2012 02:25
Show Gist options
  • Save theycallmeswift/1553169 to your computer and use it in GitHub Desktop.
Save theycallmeswift/1553169 to your computer and use it in GitHub Desktop.
Node Patterns
SomeController = (app) ->
MyModel = app.db.model 'MyModel'
# Streaming
app.get '/somethings', (req, res) ->
res.contentType('json')
somethingsStream = MyModel.find().stream()
somethingsStream.on 'data', (data) ->
res.send(JSON.stringify(data))
somethingsStream.on 'end', () ->
res.end()
# Normal
app.get '/somethingss/:id', app.m.findSomething, (req, res, next) ->
res.contentType("application/json")
res.send(JSON.stringify(req.something))
module.exports = SomethingsController
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment