最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Nodejs Express - dynamicHelpers error - Stack Overflow

programmeradmin2浏览0评论

I'm trying to run my app with the following:

app.configure(function(){
  app.set('views', __dirname + '/views');
  app.enable('jsonp callback');
  app.set('view engine', 'jade');
  app.set('view options', {layout : false});
  app.use(express.bodyParser());
  app.use(express.cookieParser());
  app.use(express.session({
    secret : 'abcdefg'      
  }));
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));

});

app.dynamicHelpers({
  session : function(req, res){
    return req.session;
  }
});

And getting the following error message when running node app.js

app.dynamicHelpers({

TypeError: Object function app(req, res){ app.handle(req, res); } has no method 'dynamicHelpers'
    at Object.<annonymous> (C:\nodeapps\nodeblox\app.js:35:5)
    at Module._pile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.Load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallBack (node.js:244:9)

Im kind of new to using nodejs but I understand that dynamicHelpers() is no longer supported with Express, I have tried re-working the code and continue to get errors all over the place. What is the correct way to fix this dynamicHelpers code so that it ensures the rest of the code is still working correctly?

Thanks!

I'm trying to run my app with the following:

app.configure(function(){
  app.set('views', __dirname + '/views');
  app.enable('jsonp callback');
  app.set('view engine', 'jade');
  app.set('view options', {layout : false});
  app.use(express.bodyParser());
  app.use(express.cookieParser());
  app.use(express.session({
    secret : 'abcdefg'      
  }));
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));

});

app.dynamicHelpers({
  session : function(req, res){
    return req.session;
  }
});

And getting the following error message when running node app.js

app.dynamicHelpers({

TypeError: Object function app(req, res){ app.handle(req, res); } has no method 'dynamicHelpers'
    at Object.<annonymous> (C:\nodeapps\nodeblox\app.js:35:5)
    at Module._pile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.Load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallBack (node.js:244:9)

Im kind of new to using nodejs but I understand that dynamicHelpers() is no longer supported with Express, I have tried re-working the code and continue to get errors all over the place. What is the correct way to fix this dynamicHelpers code so that it ensures the rest of the code is still working correctly?

Thanks!

Share Improve this question asked Nov 22, 2012 at 17:11 germainelolgermainelol 3,35115 gold badges48 silver badges83 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

I guess that you are not using Express 2 but Express 3. There is migration guide that helps you figure out what happened. For dynamicHelpers() you need to understanding that the app.use function needs to be IN the configure part, not where it was before.

Before

app.configure();
app.dynamicHelpers({
  user: function(req, res) {
    return req.session.user;
  }
});

Now in E3

app.configure(function(){
  //...
  app.use(function(req, res, next){
    res.locals.user = req.session.user;
    next();
  });
  //...
});
**In Epress3.x** there seems to be having no concept of static or dynamic.
use global or local instead.

/*Global*/
app.locals({ foo: 'bar' });
//or
app.locals.foo = 'bar';

/*For single request*/
res.locals({ foo: 'bar' });
//or
res.locals.foo = 'bar';

more difference refers Here.

发布评论

评论列表(0)

  1. 暂无评论