According to the ExpressJS application settings documentation, you should be able to set views as the directory for the view engine. I am experiencing what I think may be a bug; instead of looking in the views directory, express looks in the static directory. Obviously it fails, since it isn't there. I have confirmed this by moving the view into the static directory, and the error goes away.
You can see this bug by cloning this Cloud9 project. I have been unable to confirm this bug outside of Cloud9, (I don't have a linux box available).
The directory structure is simple
project
|-client
|-assets
|-views
|-index.html
|-server.js
here is the server config
var viewDir = __dirname + '/client/views/';
var assetDir = __dirname + '/client/assets/';
//Configure
app.configure(function() {
app.set('views', viewDir);
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express['static'](assetDir));
app.use(app.router);
});
app.get('/', function(req, res){
res.render('index');
});
You need to tell it how to render by setting an engine.
such as an echo:
app.engine('.html', function (file, options, next) {
fs.readFile(file, function (err, data) {
if (err) {
next(err);
} else {
next(null, data.toString());
}
});
});
You also need to put app.get('/' . . . before app.use(express.static if you want it to take presidence.
You can try it out here: http://runnable.com/UWTRSNJq0z5OAADk
Html files are static files whereas files in view have to be rendered by your template engine like jade or ejs. If you want to render html files then check these questions.
Template engine renders views dynamically. If you have only static pages then you wont need it. But if you have dynamic content, using templates is must.