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

*爱你&永不变心* 提交于 2019-12-07 09:05:52

问题


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
application-name@0.0.1 /Users/treejanitor/git/testapp/testapp
├── consolidate@0.3.0  extraneous
├── dust@0.3.0 
├─┬ express@2.5.8 
│ ├─┬ connect@1.8.7 
│ │ └── formidable@1.0.9 
│ ├── mime@1.2.4 
│ ├── mkdirp@0.3.0 
│ └── qs@0.4.2 
└─┬ jade@0.25.0 
  ├── commander@0.5.2 
  └── mkdirp@0.3.0

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


回答1:


I once discussed about setting up Dust.js with Express@3.0 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 Express@3.0 to work.




回答2:


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?




回答3:


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)



来源:https://stackoverflow.com/questions/10734555/node-js-express-js-dust-js-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!