在相同的js文件node.js中调用exports.start

pan*_*kaj 36 node.js

嗨,这是我在节点js文件中的方法:

exports.start = function() {
    console.log(' in start of sender.js');
});
Run Code Online (Sandbox Code Playgroud)

如何在同一个js文件中调用此方法?我试过调用start()和exports.start()但没有成功.

mic*_*nic 49

使用此代码:

var start = exports.start = function() {
   console.log(' in start of sender.js');
});
Run Code Online (Sandbox Code Playgroud)

要么

function start() {
   console.log(' in start of sender.js');
});

exports.start = start;

//you can call start();
Run Code Online (Sandbox Code Playgroud)


Ash*_*Jha 21

exports.start = function(){
    console.log('testing...')
}
Run Code Online (Sandbox Code Playgroud)

您可以像这样调用此方法

    exports.start();
Run Code Online (Sandbox Code Playgroud)


VIK*_*HLI 5

您可以像这样调用导出的函数

module.exports.functionName(arguments);