Is it possible to use static content and views from the same directory? I found a partial solution below:
app.use(express.static(__dirname + '/html'));
app.engine('.html', require('ejs').__express);
app.set('views', __dirname + '/html');
app.set('view engine', 'html');
app.listen(8000);
app.get('/', function(req,res) {
res.render('index', { message: 'hello world'});
});
app.get('/home', function(req,res) {
res.render('index', { message: 'hello world'});
});
This works fine except for the first '/' route, which does not display EJS. All other routes (/ home, / about, etc.) will conveniently serve dynamic EJS along with static content. Should I even deceive that the first "/" works the same way?
source
share