Created
May 19, 2011 21:06
-
-
Save marlun/981744 to your computer and use it in GitHub Desktop.
Using stylus with Express.js
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. | |
*/ | |
var express = require('express') | |
, stylus = require('stylus'); | |
var app = express.createServer(); | |
// This must be BEFORE other app.use | |
app.use(stylus.middleware({ | |
debug: true | |
, src: __dirname + '/views' | |
, dest: __dirname + '/public' | |
, compile: compileMethod | |
})); | |
function compileMethod(str) { | |
return stylus(str) | |
.set('compress', true); | |
}; | |
app.use(express.static(__dirname + '/public')); | |
app.set('views', __dirname + '/views'); | |
app.get('/', function(req, res){ | |
res.render('index.ejs'); | |
}); | |
app.listen(3000); | |
console.log('server listening on port 3000'); |
Nice one.
I am trying something similar but its not working. I also noticed that when I simply copy & paste this code, I get an express error that createServer()
is deprecated (or similar). I changed it to express()
to fix the problem but requests to /css/styles.css
is always not found ...
Posted a question on StackOverflow: http://stackoverflow.com/questions/14078019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got it from http://subprint.com/blog/getting-past-pathing-issues-stylus-and-express-js/