Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js + express.js + dust.js issues

The quick question: why won't express.js run with dust.js?
I know it's not officially supported, but dust.js even has issues with my node.js version.
Node won't even start due to require.path issues.

server:testapp treejanitor$ node --version
v0.6.12

I get issues when setting the app engine to dust. (app.js in express)

var dust = require('dust');
...
app.set('view engine', 'dust');

I'm showing the console here to give you my simple list of modules.
Also someone searching for the same problem might cut/paste the error.

server:hummr treejanitor$ npm list
[email protected] /Users/treejanitor/git/testapp/testapp
├── [email protected]  extraneous
├── [email protected] 
├─┬ [email protected] 
│ ├─┬ [email protected] 
│ │ └── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ └── [email protected] 
└─┬ [email protected] 
  ├── [email protected] 
  └── [email protected]

server:testapp treejanitor$ supervisor app.js

DEBUG: Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead.
    at Function.<anonymous> (module.js:378:11)
    at Object.<anonymous> (/Users/treejanitor/git/testapp/testapp/node_modules/dust/lib/server.js:6:8)

I tried the following attempt with no luck:
Dust.js load template from filesystem in Node.js

NOTE: I tried the alpha version of express (3.0) which didn't help.
Same goes for consolidate.js and all the modules in that example.


Some reasons why I am interested in node + express + dust:
LinkedIn picks dustjs
Twitter's Bootstrap framework

like image 977
treejanitor Avatar asked May 24 '12 09:05

treejanitor


3 Answers

I once discussed about setting up Dust.js with [email protected] on Node.js 0.6.x through the consolidate.js module. You can read it here

However, you may want to use LinkedIn's fork of Dust.js, which supports Node.js 0.6.x out of the box with other improvements.

Consolidate.js already supports that fork, but you still need [email protected] to work.

like image 173
Sơn Trần-Nguyễn Avatar answered Oct 24 '22 02:10

Sơn Trần-Nguyễn


So here's the trick - I thought I'd share what I found.
It required finding this nugget - search for dust-x in the page if you're interested. http://nodejs.debuggable.com/2012-03-23.txt

To resolve things, in your express app

cd node_modules
git clone git://github.com/laurie71/dust-x.git
git clone https://github.com/caolan/dustjs.git

The fork of dust.js resolving the require.paths issue with node.js
https://github.com/caolan/dustjs

The 'wrapper' of dust making it available as a template engine
(You'll still need dust.js installed as a module)
https://github.com/laurie71/dust-x

The example usage
https://gist.github.com/2174537

Most important bit:

var dustx = require('dust-x');

...

// Configuration

app.configure(function(){
    app.set('views', __dirname + '/views');
    app.register('.dust', dustx/*({})*/);
    app.set('view engine', 'dust');
    // app.set('view engine', 'jade');
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(app.router);
    app.use(express['static'](__dirname + '/public'));
});

Btw, I think I could have manually fixed the dust.js issue inside its server.js but I wanted to give kudos to the person who actually forked dust.js and made the solution publicly available.


PS: I'm still fairly new to posting on stackoverflow, so if I've breached some etiquette just let me know. I read in the FAQ that answering your own questions is encouraged, so I thought I'd give it a try.

In particular, I know my formatting is probably weak. In the answer, I actually preferred showing the full link rather than the guide-suggested URL embedding because it reveals structure of the containing sites. With the site URL soaked up in your brain, it gives you more opportunity to the site as reference the next go-around. Also the URLs were reasonably short. ;^) Suggestions are greatly appreciated.

What is the way a 'console' is typically formatted? As code?

like image 41
treejanitor Avatar answered Oct 24 '22 02:10

treejanitor


It could be an issue with node.js and express.js versions..I am using node v0.10.9 and express v3.0.x and they work well for me. For integrating dust.js with express.js and node.js, I found this github repo to be a useful resource to help you get started with: https://github.com/chovy/express-template-demo (It uses the linkedin fork of dust.js)

like image 34
learner_19 Avatar answered Oct 24 '22 04:10

learner_19