我刚刚使用自制软件安装了nodejs。
然后我创建了一个文件夹,并安装了express:
npm install -g express
然后我使用以下方法创建了一个新项目:
express -H --css less --sessions foo
现在,当我尝试运行应用程序时:
node app.js
我明白了:
/Users/blah/dev/testing/nodetest1/foo/node_modules/less-middleware/lib/middleware.js:50
throw new Error('Please update your less-middleware usage: http://goo.gl/Y
^
Error: Please update your less-middleware usage: http://goo.gl/YnK8p0
at module.exports.less.middleware (/Users/blah/dev/testing/nodetest1/foo/node_modules/less-middleware/lib/middleware.js:50:11)
at Object.<anonymous> (/Users/snad/dev/testing/nodetest1/foo/app.js:26:35)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
我的app.js看起来像:
/**
* Module dependencies.
*/
var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hjs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session());
app.use(app.router);
app.use(require('less-middleware')({ src: path.join(__dirname, 'public') }));
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
app.get('/', routes.index);
app.get('/users', user.list);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
答案 0 :(得分:30)
我更改了以下行:
app.use(require('less-middleware')({ src: path.join(__dirname, 'public') }));
为:
app.use(require('less-middleware')(path.join(__dirname, 'public')));
现在可以使用了。奇怪的是这是一个全新的应用程序,全新安装了nodejs和express。
答案 1 :(得分:0)
我评论了
app.use(require('less-middleware')({ src: path.join(__dirname, 'public') }));
完全取得了相同的结果。我觉得我们破坏了某种功能。