Noah
Noah

Reputation: 4751

In an Express controller, use a function that the current controller exports

I'd like to do this in my main-controller.js file:

var mainController = require( './main-controller' )

exports.add = function ( a, b ) {

    return a + b

}

exports.showAdded ( req, res ) {

    return res.json( mainController.add( req.query.a, req.query.b ) )

}

But requiring and referencing the current controller seems weird. Is there a way to do something like this instead?

this.add( req.query.a, req.query.b )

Upvotes: 0

Views: 41

Answers (1)

beautifulcoder
beautifulcoder

Reputation: 11320

Why not var it:

var add = function (a, b) { };

exports.add = add;

Upvotes: 1

Related Questions