how touse module exports code example
Example 1: What is the syntax to export a function from a module in Node.js
function foo() {}
function bar() {}
// To export above functions:
module.exports = foo;
module.exports = bar;
// And in the file you want to use these functions,
// import them like this:
const foo = require('./module/path');
const bar = require('./module/path');
Example 2: module.exports vs exports
//module.exports used for object
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 used for function
exports.SimpleMessage = 'Hello world';