user4445419
user4445419

Reputation:

call to private in node with js

im using the following code in a node application and I got error when I call to _valdations function, I want that _vali will be "private" like (I know that this is not supported native with JS,what is the recomended way to do so ? the vali function should be not exposed outside (just use for internal ...)

module.exports = {


        fileAction: function (req, res, urlPath) {

           ....
                  _validations(config, req, res);




        },

        _vali: function (config, req, res) {

          do some validations
        },

    };

Upvotes: 0

Views: 26

Answers (2)

Constantinius
Constantinius

Reputation: 35069

Just don't add it to the module.exports:

var _vali = function (config, req, res) {
    // do some validations
}

module.exports = {
   fileAction: function (req, res, urlPath) {
      _vali(config, req, res);
    }
};

Upvotes: 1

Quentin
Quentin

Reputation: 944084

Don't export it. Just use it as a local variable.

function fileAction(etc) {

}

function vali(etc) {

}

module.exports = {
    fileAction: fileAction
    // vali: vali // Not exported
};

Upvotes: 1

Related Questions