I installed a configuration file to store settings such as the application path, cookie secret, etc. for my express application. The problem is that this seems to be ignoring the settings of the view path directory.
config.js:
...
exports.server = {
port: 3000,
cookie_secret: ".....",
path: "/var/www/onmynode-dev/"
}
...
app.js:
...
app.set('views', path.join(config.server.path, 'views'));
app.set('view engine', 'html');
app.engine('html', require('express3-handlebars')({defaultLayout: "default.html"}));
...
The route is configured as follows:
app.get('/', routes.index);
The view is called from the request as follows:
exports.index = function(req, res){
res.render('index');
};
console.log of the application object (var app = express ();) at the very end of my app.js.
...
settings:
{ 'x-powered-by': true,
etag: true,
env: 'development',
'subdomain offset': 2,
view: [Function: View],
views: '/var/www/onmynode-dev/views',
'jsonp callback name': 'callback',
'json spaces': 2,
port: 3000,
'view engine': 'html'
},
...
So, it seems that the view is set correctly, but when you start the application and load the page, we get the following:
500 Error: ENOENT, open '/home/user/views/layouts/default.html'
So it looks like the __dirname variable is being used, regardless of how I set it. Question: how do I debug / fix this problem?