Created
August 27, 2012 14:32
-
-
Save m9dfukc/3488985 to your computer and use it in GitHub Desktop.
express.js coffeescript skeleton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
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