clyfe / tweet_express

Express sample app in CoffeeScript with a cube of sugar (superseded by umbrella)

Home Page:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


(Will evolve into an express-* umbrella framework)

Application kikstart for Express + Mongoose in CoffeeScript with a thin sintactic sugar layer and minimal structure.
Makes writing small-ish Express apps in CoffeeScript a little better.


  • Controller objects that you can use as MVC or plain Express routes callbacks
  • niceties to make code less verbose, less typing, cleaner code
  • nice MVC structure inspired by Rails
  • flexible conventions
  • base application skeleton
  • CoffeeScript all the way down (CSON for language translations, CoffeeKup for views)


Routing example

# app/
module.exports = ->

  # Can use function callbacks that run inside of a controller context
  @get '/', to: ->
    @title = "Hello route function!"
    @render 'index'

  # Can use controller actions callbacks
  @get '/tweets', to: 'tweets#index'
  @post '/tweets', to: {controller: 'tweets', action: 'create'}
  # Namespaces
  @namespace '/admin', ->
    # Can use REST routing via express-resource
    @resource 'users'
    @get '/test', to: ->
      @title = "Hello namespace!"
      @render 'index'

Controller example

# app/controllers/
Controller = require 'sugar_cube/controller'
Tweet = require 'models/tweet'

class Tweets extends Controller
  @action index: ->
    Tweet.find (@err, @tweets) => @render 'tweets/index'
  @action create: ->
    @tweet = new Tweet @param 'tweet' (@err) => @redirect 'back'

module.exports = Tweets

Views example

# views/
h1 -> @title
# views/tweets/
h1 -> 'Express'

for tweet in @tweets
  p -> tweet.body

form action: "/tweet", method: "post", ->
  input type: "text", name: "tweet[body]"
  input type: "submit"

Look at the code in the lib/ folder to see the code making these posible, it's nicely documented.

Code reload

  1. Via cluster reload
  • coffee (see file)
  1. Via node-supervisor
  • install sudo npm install supervisor -g
  • run with supervisor


See node-inspector

coffee --nodejs --debug

File structure

  client/ - client specific modules (via browserify) - client main (see browserify)
  controllers/ - controller files
  locales/ - I18n CSON files (or JSON)
  models/ - Mongoose models
  views/ - CoffeeKup view files
    layouts/ - layout files - default layout
      ... - environment configuration, middleware, database connection - view helpers here - routes definitions
lib/ - library code - server boot and configuration - cluster support

Coming soon


Express sample app in CoffeeScript with a cube of sugar (superseded by umbrella)


Language:CoffeeScript 100.0%