Mit dieser Methode können Sie set()
die Standardeinstellungen von Express neu definieren.
app.set('views', path.join(__dirname, '/yourViewDirectory'));
Für eine dynamische Pfadänderung können Sie Folgendes tun:
var express = require('express');
var path = require('path');
var app = express();
app.engine('jade', require('jade').__express);
app.set('view engine','jade');
app.customRender = function (root,name,fn) {
var engines = app.engines;
var cache = app.cache;
view = cache[root+'-'+name];
if (!view) {
view = new (app.get('view'))(name, {
defaultEngine: app.get('view engine'),
root: root,
engines: engines
});
if (!view.path) {
var err = new Error('Failed to lookup view "' + name + '" in views directory "' + root + '"');
err.view = view;
return fn(err);
}
cache[root+'-'+name] = view;
}
try {
view.render(opts, fn);
} catch (err) {
fn(err);
}
}
app.get('/', function(req, res) {
app.customRender(path.join(__dirname, '/path/to/user/'),'index',function (err,html) {
if (err)
res.send(404);
else
res.send(200,html);
});
});
app.listen(3000);