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');
function foo(x, y) {
return x + y;
}
function bar(x, y) {
return x - y;
}
//You can also export numbers, classes, objects, etc
const foobar = 33;
module.exports = { foo, bar, num };
module.exports ={
//functions
}
var users = [
{ userName: "BarneyRubble", age: 38 },
{ userName: "WilmaFlintstone", age: 37 },
{ userName: "FredFlintstone", age: 36 }
];
module.exports.getAllUsers = function(){
return users;
}
module.exports.yourFunctionName = function()
{
}
require function returns exports of the require module.
module.exports is the returned object.
1)use module.exports to export single varibale e.g one class or one function
e.g module.exports= Calculator.
2)use exports to export multiple named variables
export.add = (a,b)=> a+b;
export.multiple=(a,b)=> a*b;