Mohamed Challouf
Mohamed Challouf

Reputation: 113

How route restify calls to function written in another file

I have a file that launch nodejs/restify server, when calls arrive to my server i do this:

apiserver.post('/:param',call1);

function call1(req, res, next) {
//treatment
}

But i want to place my functions in a script called functions.js, the problem is when i do this

var functions = require('./functions')
apiserver.post('/:param', functions.call1(req,res,next));

it say that req, res and next is undefiened variables.

Upvotes: 1

Views: 734

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 312095

The problem is that you're calling functions.call1 in your apiserver.post call when what you want to do is pass the function itself as a parameter:

apiserver.post('/:param', functions.call1);

Upvotes: 1

Related Questions