xxxxxxxxxx
var users = [
{ userName: "BarneyRubble", age: 38 },
{ userName: "WilmaFlintstone", age: 37 },
{ userName: "FredFlintstone", age: 36 }
];
module.exports.getAllUsers = function(){
return users;
}
xxxxxxxxxx
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');
xxxxxxxxxx
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 };
xxxxxxxxxx
module.exports = {
method: function() {},
otherMethod: function() {},
};
const myModule = require('./myModule.js');
const method = myModule.method;
const otherMethod = myModule.otherMethod;
// OR:
const {method, otherMethod} = require('./myModule.js');
xxxxxxxxxx
mycoolmodule/index.js
module.exports = "123";
routes/index.js
var mymodule = require('mycoolmodule')
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
console.log(mymodule);
});
/*will show 123 in the terminal*/
module.exports = router;
xxxxxxxxxx
module.exports.name = value; // to export something
require( path_to_module ).name; // to import something
xxxxxxxxxx
let value = "string bir ifade"
let number = 54;
module.exports = value /!bu şekildede oluyor
module.exports = value