1

I'm trying to use Dustjs with Express but encountering a problem. Here my code:

var express = require('express')
  , bodyParser = require('body-parser')
  , cons = require('consolidate')
  , app = express();


app.engine('html', cons.dust);
app.set('view engine', 'dust');
app.set('views', __dirname + '/views');

app.use(bodyParser());

app.get('/', function (req, res) {
  res.render('home', { name: 'Tom' });
})

app.listen(4000);

and dependencies:

  "dependencies": {
    "express": "4.x",
    "body-parser": "*",
    "consolidate": "*",
    "dustjs-linkedin": "*",
    "dustjs-helpers": "*"
  },

When I run the code, an error message showed up

Error: Cannot find module 'dust'

I don't get it. Any ideas would be appreciated. Thanks.

Phieu
  • 77
  • 5

1 Answers1

2

The original dust module have been deprecated, and consolidate does not support dustjs-linkedin.
A suggestion is to use Adaro, created by PayPal for KrakenJS.

Sample code:

var dustjs = require('adaro');    
var app = express();

app.engine('dust', dustjs.dust({});
app.set('view engine', 'dust');

with info from here

Community
  • 1
  • 1
gustavohenke
  • 40,997
  • 14
  • 121
  • 129
  • Thanks. I got it working. Another question, I don't want the template's extension is ".dust" by default. Is there any way to change that? – Phieu May 08 '14 at 14:20
  • Just change the call to `app.engine` to use what you want. See [here](http://expressjs.com/3x/api.html#app.engine) for reference – gustavohenke May 08 '14 at 14:39
  • I changed it to `app.engine('html', dustjs.dust({}))`, but the message showed up again. – Phieu May 08 '14 at 15:15
  • Seems like `view engine` is the default engine to use when your call to `res.render()` misses the extension. So you'll have to set it to html as well ([ref](http://expressjs.com/3x/api.html#app-settings)) – gustavohenke May 08 '14 at 20:08
  • I changed that as well but another error: `Error: ENOENT, open '/home/abc/Dropbox/Express/webapp/app/views/home.dust'` It seems like it still looks up the .dust file – Phieu May 09 '14 at 07:59