node.js - Using lessjs with express 3 -
i new nodejs , related it. using twitter-bootstrap framework node js. ran following commands -
npm install -g twitter-bootstrap-node twitter-bootstrap create myproject
this using express 2 default upgraded express 3. since getting following error when start express-
$ node app warning: express.createserver() deprecated, express applications no longer inherit http.server, please use: var express = require("express"); var app = express(); /users/tusharmathur/pebbles/app.js:17 app.use(express.compiler({ ^ typeerror: object function createapplication() { var app = connect(); utils.merge(app, proto); app.request = { __proto__: req }; app.response = { __proto__: res }; app.init(); return app; } has no method 'compiler' @ function.app.configure.app.use.express.errorhandler.dumpexceptions (/users/tusharmathur/pebbles/app.js:17:19) @ function.app.configure (/users/tusharmathur/pebbles/node_modules/express/lib/application.js:395:61) @ object.<anonymous> (/users/tusharmathur/pebbles/app.js:12:5) @ module._compile (module.js:456:26) @ object.module._extensions..js (module.js:474:10) @ module.load (module.js:356:32) @ function.module._load (module.js:312:12) @ function.module.runmain (module.js:497:10) @ startup (node.js:119:16) @ node.js:903:3
here app.js file
/** * module dependencies. */ var express = require('express'), routes = require('./routes'); var app = module.exports = express.createserver(); // configuration app.configure(function() { app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.bodyparser()); app.use(express.methodoverride()); app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] })); app.use(app.router); app.use(express.static(__dirname + '/public')); }); app.configure('development', function() { app.use(express.errorhandler({ dumpexceptions: true, showstack: true })); }); app.configure('production', function() { app.use(express.errorhandler()); }); // compatible // less files @import 'whatever.less' work(https://github.com/senchalabs/connect/pull/174) var twitter_bootstrap_path = './vendor/twitter/bootstrap/less'; express.compiler.compilers.less.compile = function(str, fn) { try { var less = require('less'); var parser = new less.parser({ paths: [twitter_bootstrap_path] }); parser.parse(str, function(err, root) { fn(err, root.tocss()); }); } catch (err) { fn(err); } } // routes app.get('/', routes.index); app.listen(3000, function() { console.log("express server listening on port %d in %s mode", app.address().port, app.settings.env); });
as message says, express not have compiler message anymore. should use middleware allows build less files. 1 example less.js-middleware.
after installing (npm install less-middleware
) can use demonstrated in documentation:
var lessmiddleware = require('less-middleware'); var app = express.createserver(); app.configure(function () { app.use(lessmiddleware({ src: __dirname + '/public', compress: true })); });
Comments
Post a Comment