Reputation: 21352
this is the code I have
var express = require('express');
var app = express();
app.set('view engine', 'jade');
app.set('views', __dirname + '/views');
exports.makeObservable = function(state, path, cb) {
app.get(path, function(req, res){
res.render('observable.jade', state);
//call callback with new user
cb(req);
});
app.listen('9999');
}
Whenever I try to reach the path
I receive the following error:
Error: Failed to lookup view "observable.jade"
. I also tried to pass observable
without the .jade
but it gives the same error. I have both observable.jade and layout.jade in my /views
folder.
What am I missing? Thanks!
Upvotes: 1
Views: 6492
Reputation: 333
FWIW: I have my views in an adjacent directory (ie root/server, root/client), and was having the same issues described here. The one thing I did differently than the OP, was to prepend a '/' in my app.set when climbing out of the server directory; ie:
this: app.set('views', __dirname + '/../client/');
instead of: app.set('views', __dirname + '../client/');
HTH
(Thanks a TON to the OP and Pickels!)
Upvotes: 2
Reputation: 21352
I finally solved the problem thanks to the suggestions in the comments. First of all I checked if the directory from which the script was executing contained the directory /views
where I put the .jade
files. I couldn't solve the problem at first since I couldn't figure from which this script was executed, so I put a console.log(view)
at line 493 in /express/lib/application.js
. It printed out the view
object that contained the root from which the script was executed, thus I moved the /views
folder there and everything worked.
Upvotes: 2