0

I am trying out doT.js for the first time and have written a very basic server setup:

'use strict';

var express = require('express');
var app = express();
var doT = require('express-dot');

var pub = __dirname+'/public';
var vws = __dirname+'/views';

app.set('views', vws);
app.set('view engine', 'dot');
app.engine('html', doT.__express);

app.use('/css',express.static(pub + '/css'));
app.use('/img',express.static(pub + '/imgs'));
app.use('/js',express.static(pub + '/js'));

app.get('/', function(req, res){
    res.render(vws + '/index.html', { title: 'dynamic title' });
});

app.listen(8080);
console.log('Server running on port 8080');

When I run the server and goto myaddress:8080 I get the following error: Error: ENOENT, open '/home/myproject/views/layout.html'

If I try calling index.html with res.sendFile it works (although of course I can't pass variables that way)

res.sendFile(vws + '/index.html')

Where am I going wrong? Why am i getting an error which seems to relate to a failed attempt at opening "layout.html" when no example I have seen mentions such a file?

I need to use res.render in order to pass variables to the template, but all the examples I have found do it the same way I tried in my first attempt.

Matthew James Davis
  • 12,134
  • 7
  • 61
  • 90
Finglish
  • 9,692
  • 14
  • 70
  • 114
  • 1
    i don't think dot has an express module, unless it was added recently? – Matthew James Davis Dec 01 '14 at 03:23
  • @MatthewJamesDavis Looks like you are right for express 4. Checked the npm package data for express-dot and it does say 3.x. Thats a shame, I was planning on using doT for the speed. Without the express module, what is the best way to use it? Or is there an alternative engine that is comparable is speed? – Finglish Dec 01 '14 at 07:30
  • you can use Jade or Ejs, that should work fine. – NarendraSoni Dec 01 '14 at 09:01
  • @NarendraSoni I am not sure about Ejs, but I know that Jade is significantly slower the doT.js which is why I first chose it. – Finglish Dec 01 '14 at 10:42
  • ect looks interesting, especially as they include a very impressive benchmark comparrison table http://ectjs.com/#benchmark, anyone used it? – Finglish Dec 01 '14 at 10:48
  • 1
    I like using swig. It isn't the fastest but its quite fully featured. – Matthew James Davis Dec 01 '14 at 15:06
  • @MatthewJamesDavis Swig isn't the fastest bet its quite a lot faster then Jade and the feature list looks good, I will give it a try – Finglish Dec 01 '14 at 18:51

1 Answers1

0

dot.js isn't yet integrated with express 4.0's view engine middleware hook.

Swig is a similar application that is. It isn't quite as fast as dot.js, but for me it has a great balance of speed and features with an extremely intuitive syntax.

Full disclosure: I like swig.

Matthew James Davis
  • 12,134
  • 7
  • 61
  • 90