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 badges2 Answers
Reset to default 5I 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.