I'm writing my first nodejs/expressjs application ( at this tutorial: nettuts+ ) and I get stucked with this simple but annoing error. What I'm trying to do is simple, i just created my app project by typing in the command line (express --sessions --css less --hogan app) and it created for me this structure:
/public
/images
/javascripts
/stylesheets
style.less (It came with a style.less)
/routes
/index.js
/user.js
/views
/index.hjs
/app.js
/package.json
Ok until now.
I used my WinLess (for I use windows 8) to compile the style.less and it created the style.css successfully.
But when I start the server (node app) I got me this error in the command line and browser (just when i try to access the 127.0.0.1:3000/stylesheets/style.css):
Express
500 TypeError: Arguments to path.join must be strings
at f (path.js:204:15)
at Object.filter (native)
at Object.exports.join (path.js:209:40)
at Object.handle (c:\Users\Welder Lourenço\Desktop\WEB\learningexpress\app\node_modules\less- middleware\lib\middleware.js:128:26)
at next (c:\Users\Welder Lourenço\Desktop\WEB\learningexpress\app\node_modules\express\node_modules\connect\lib\proto.js:193:15)
at c:\Users\Welder Lourenço\Desktop\WEB\learningexpress\app\node_modules\express\node_modules\connect\node_modu les\express-session\index.js:350:9
at Object._onImmediate (c:\Users\Welder Lourenço\Desktop\WEB\learningexpress\app\node_modules\express\node_modules\connect\node_modu les\express-session\session\memory.js:50:9)
at processImmediate [as _immediateCallback] (timers.js:330:15)
And in the command line it appears this error too:
GET /stylesheets/style.css 500
I really dont know what to do, can someone help me please? Here, follows my codes.
/**
* 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(require('less-middleware')({ src: __dirname + '/public' }));
app.use(express.static(process.cwd() + '/public'));
app.use(app.router);
// 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'));
});
Expressjs version: 3.5.0 Nodejs version: 0.10.26 OS: windows 8
I had the same issue.
Try replacing the line:
app.use(require('less-middleware')({ src: __dirname + '/public' }));
with
app.use(require('less-middleware')(__dirname + '/public'));
I am referencing the format outlined on the less-middleware page
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With