Skip to content

Instantly share code, notes, and snippets.

@borestad
Created December 5, 2012 23:39
Show Gist options
  • Save borestad/4220542 to your computer and use it in GitHub Desktop.
Save borestad/4220542 to your computer and use it in GitHub Desktop.
Express.js boilerplate - Not as pretty as Zappajs, but still more readable?
express = require 'express'
engines = require 'consolidate'
routes = require './routes'
app = express()
exports.startServer = ((config) ->
server = @listen config.server.port, ->
console.log "Express server listening on port %d in %s mode", server.address().port, app.settings.env
# Main configuration
@configure ->
@set 'port', config.server.port
@set 'views', config.server.views.path
@engine config.server.views.extension, engines[config.server.views.compileWith]
@set 'view engine', config.server.views.extension
@use express.favicon()
@use express.bodyParser()
@use express.methodOverride()
@use express.compress()
@use config.server.base, @router
@use express.static(config.watch.compiledDir)
# Development configuration
@configure 'development', ->
@use express.errorHandler()
# Routes
@get '/', routes.index(config)
server
).bind(app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment