node.js - make request and response available in scope node js -


i have module.exports

module.exports = {   defaultstrings: function() {     return "hello world" +            "foo - bar";   },   urlslug: function(s) {     return s.tolowercase().replace(/[^\w\s]+/g,'').replace(/\s+/g,'-');   } }; 

i want able use request or response inside function defaultstrings how include minimum change of given code?

  defaultstrings: function(req, res, next) { // <--- not working says cannot call method 'someglobalfunction' of undefined     return "hello world" +            "foo - bar" + req.someglobalfunction();   }, 

in app.js require file in

strings = require('./lib/strings'), 

and how being called inside app.js

app.get('/',         middleware.setsomeoperation,         routes.index(strings); 

when calling defaultstrings? if calling directly routes i.e. using app.get("some_url", defaultstrings), req , res should available you.

edit: appears calling by: content = strings.defaultstrings(); inside of index function. in order pass on req , res arguments must change call content = strings.defaultstrings(req,res,cb), cb callback defined index.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -