Skip to content

Instantly share code, notes, and snippets.

@marlun
Created May 19, 2011 21:06
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marlun/981744 to your computer and use it in GitHub Desktop.
Save marlun/981744 to your computer and use it in GitHub Desktop.
Using stylus with Express.js
/**
* 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');
@marlun
Copy link
Author

marlun commented May 19, 2011

@joemccann
Copy link

Nice one.

@jiewmeng
Copy link

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