Created
December 21, 2011 07:52
-
-
Save dtan/1505124 to your computer and use it in GitHub Desktop.
basic set up - express for node.js
This file contains hidden or 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
var express = require('express'); | |
app = module.exports = express.createServer(), | |
viewEngine = 'jade', | |
stylus = require('stylus'), | |
nib = require('nib'); | |
app.configure('development', function(){ | |
var stylusMiddleware = stylus.middleware({ | |
src: __dirname + '/stylus/', // .styl files are located in `/stylus`, must match /public folder structure | |
dest: __dirname + '/public/', // .styl resources are compiled `/stylesheets/*.css` | |
debug: true, | |
compile: function(str, path) { // optional, but recommended | |
return stylus(str) | |
.set('filename', path) | |
.set('warn', true) | |
.set('compress', true) | |
.use(nib()); | |
} | |
}); | |
app.use(stylusMiddleware); | |
app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); | |
}); | |
app.configure('production', function(){ | |
app.use(express.errorHandler()); | |
}); | |
app.configure(function(){ | |
app.set('views', __dirname + '/views/' + viewEngine); | |
app.set('view engine', viewEngine); | |
app.use(express.logger(':method :url :status')); | |
app.use(express.bodyParser()); | |
app.use(express.methodOverride()); | |
app.use(app.router); | |
app.use(express['static'](__dirname + '/public')); | |
app.dynamicHelpers({ | |
isDevMode: function (req, res) { | |
return (process.env.NODE_ENV || 'development') === 'development'; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment