Javascript NodeJS中的Module.exports,输出功能

Javascript NodeJS中的Module.exports,输出功能,javascript,node.js,Javascript,Node.js,module1.js module.exports = function (input, input2) { return "exported"; }; var module1 = require('/Users/Aakarsh/Desktop/Node/ToDo/playground/module1.js'); console.log(module1); var myfunction= function() { ... }; exports.myfunction= myfunct

module1.js

module.exports = function (input, input2) {

  return "exported";

};
var module1 = require('/Users/Aakarsh/Desktop/Node/ToDo/playground/module1.js');

console.log(module1);
var myfunction= function() { ... };
exports.myfunction= myfunction;
var m = require('./a'); // require includes file by which function will be available
m.myfunction(); // Once function is available you can call 
            //just like normal JavaScript function
modulegetter.js

module.exports = function (input, input2) {

  return "exported";

};
var module1 = require('/Users/Aakarsh/Desktop/Node/ToDo/playground/module1.js');

console.log(module1);
var myfunction= function() { ... };
exports.myfunction= myfunction;
var m = require('./a'); // require includes file by which function will be available
m.myfunction(); // Once function is available you can call 
            //just like normal JavaScript function
输出内容:
[功能]

我希望它像在
module1.js
类中一样输出
“导出的”
。我能做什么

额外:

当我有这个时,在
modulegetter.js

var f = function (input, input2) {

    return "exp";

};

console.log(f("f", "f"));

它根据需要输出
exp
,但为什么它不能与module.exports一起工作?

您需要实际调用函数(带或不带参数):


module.exports
公开可从其他文件访问的外部方法或变量。假设您有两个文件a.js和b.js

a.js

module.exports = function (input, input2) {

  return "exported";

};
var module1 = require('/Users/Aakarsh/Desktop/Node/ToDo/playground/module1.js');

console.log(module1);
var myfunction= function() { ... };
exports.myfunction= myfunction;
var m = require('./a'); // require includes file by which function will be available
m.myfunction(); // Once function is available you can call 
            //just like normal JavaScript function
b.js

module.exports = function (input, input2) {

  return "exported";

};
var module1 = require('/Users/Aakarsh/Desktop/Node/ToDo/playground/module1.js');

console.log(module1);
var myfunction= function() { ... };
exports.myfunction= myfunction;
var m = require('./a'); // require includes file by which function will be available
m.myfunction(); // Once function is available you can call 
            //just like normal JavaScript function

模块1和模块1()之间的区别是什么?
module1()
执行/调用函数,
module1
只是对函数的引用,并返回函数本身,而不是其结果/返回。