Skip to content

Instantly share code, notes, and snippets.

@mburakerman
Created June 24, 2017 12:49
Show Gist options
  • Save mburakerman/87bce1d1b4f59aec3ad95c02e0edaf6b to your computer and use it in GitHub Desktop.
Save mburakerman/87bce1d1b4f59aec3ad95c02e0edaf6b to your computer and use it in GitHub Desktop.
Node.js module exports and require
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
}
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