Created
January 21, 2020 23:47
-
-
Save prof3ssorSt3v3/674c7abe65ac46383fd4f639506287ef to your computer and use it in GitHub Desktop.
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
//How to export and require modules with NODE JS | |
const fs = require("fs"); | |
//const f = require("./module1.js") | |
// const mod = require("./module1"); | |
const { f, P } = require("./module1"); | |
//const y = require("./module2/bubba.js"); | |
//const y = require("./module2/bubba"); | |
const y = require("./module2"); | |
f(); | |
//mod.x(); | |
console.log(P); | |
y(); |
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
const y = function() { | |
console.log("function y"); | |
}; | |
const PIE = 3.14; | |
module.exports = y; |
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
const f = function() { | |
console.log("This is function f inside module1.js"); | |
}; | |
const x = function() { | |
console.log("This is function x inside module1.js"); | |
}; | |
const P = 3.14; | |
//module.exports = f; | |
// module.exports.f = f; | |
// module.exports.x = x; | |
// module.exports.P = P; | |
module.exports = { f, x, P }; |
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
{ | |
"name": "module2", | |
"version": "1.0.0", | |
"description": "", | |
"main": "bubba.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment