如何从Node.Js app中引用exports函数?

问题描述 投票:0回答:1

假设我在我的Node.Js应用程序的exports中有以下validate.js函数:

exports.stopwordsClean = function () {
    return function(req, res, next){
        console.log("validating...");
    }
};

我明白,从另一个文件引用这个函数我会首先require这个文件,然后使用validate.stopwordsClean()

但是如何从同一个文件中引用它呢? this.stopwordsClean()不起作用......

javascript node.js include
1个回答
0
投票

exportsmodule中的一个对象。当你写exports.stopwordsClean = function () {..时,你正在设置stopwordsClean对象的属性exports。因此你可以随时使用

exports.stopwordsClean()

在同一个模块中使用该功能。

© www.soinside.com 2019 - 2024. All rights reserved.