Created
June 24, 2017 12:49
-
-
Save mburakerman/87bce1d1b4f59aec3ad95c02e0edaf6b to your computer and use it in GitHub Desktop.
Node.js module exports and require
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let person = { | |
age:23, | |
name:"Mehmet Burak Erman", | |
show: function() { | |
return this.name; | |
} | |
} | |
function foo() { | |
return 'foo!' | |
} | |
module.exports.person = person; | |
module.exports.foo = foo; | |
/* == OR ==*/ | |
module.exports = { | |
"person":person, | |
"foo":foo | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let lib= require('./lib.js'); | |
console.log(lib.foo()); // > foo! | |
console.log(lib.person.age); // > 23 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment