Reputation: 841
I want to add a script in app.js file here is the code:
app.helpers({
renderScriptsTags: function (all) {
if (all != undefined) {
return all.map(function(script) {
return '<script src="/javascript/' + script + '"></script>';
}).join('\n ');
}
else {
return '';
}
}
});
app.dynamicHelpers({
scripts: function(req, res) {
return ['canvasjs.min.js'];
}
});
while executing its give me an error shown below:
app.helpers({
^
TypeError: Object function (req, res, next) {
app.handle(req, res, next);
} has no method 'helpers'
at Object.<anonymous> (/var/www/html/nodeproject/helloworld/index.js:27:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
Upvotes: 0
Views: 1261
Reputation: 1787
As your error is showing app
does not have helper
funtion. Memeber functions of app are listed here http://expressjs.com/en/api.html
if you want to use helpers you will have to create them explicity like
//helper.js
module.export = function(){
// Your logic here
};
//usage
var helper = require('./relative/path/to/helper');
var getValueFromHelper = helper();
hope it helps :)
Upvotes: 1