Skip to content

Instantly share code, notes, and snippets.

@m9dfukc
Created August 27, 2012 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m9dfukc/3488985 to your computer and use it in GitHub Desktop.
Save m9dfukc/3488985 to your computer and use it in GitHub Desktop.
express.js coffeescript skeleton
###
Module dependencies.
###
express = require 'express'
http = require 'http'
app = module.exports = express()
server = http.createServer app
###
Modules paths
###
routes = './routes'
database = './database'
###
Database Options
###
db_options =
schema: process.env.DATABASE_NAME
user: process.env.DATABASE_USER
password: process.env.DATABASE_PASSWORD
host: process.env.DATABASE_HOST
port: process.env.DATABASE_PORT
logging: console.log
###
Configuration
###
app.configure ->
app.use express.bodyParser()
app.use express.methodOverride()
app.use app.router
app.configure 'development', ->
app.use express.errorHandler dumpExceptions: true, showStack: true
db_options.logging = console.log
app.configure 'production', ->
app.use express.errorHandler
db_options.logging = false
###
Models
###
app.db = require(database) db_options
###
Routes
###
app.get '/', (req,res) ->
res.render 'index', {title: 'Express'}
###
Http Server
###
if !module.parent
server.listen process.env.PORT or 3000
console.log "Express listening on port #{server.address().port}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment