module exports js code example
Example 1: What is the syntax to export a function from a module in Node.js
function foo() {}
function bar() {}
module.exports = foo;
module.exports = bar;
const foo = require('./module/path');
const bar = require('./module/path');
Example 2: how to export module in node js
module.exports ={
}
Example 3: module.exports vs exports
var log = {
info: function (info) {
console.log('Info: ' + info);
},
warning:function (warning) {
console.log('Warning: ' + warning);
},
error:function (error) {
console.log('Error: ' + error);
}
};
module.exports = log
exports.SimpleMessage = 'Hello world';
Example 4: module.exports equivalent es6
exports["default"] = A; module.exports = exports["default"];