Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created January 21, 2020 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prof3ssorSt3v3/674c7abe65ac46383fd4f639506287ef to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/674c7abe65ac46383fd4f639506287ef to your computer and use it in GitHub Desktop.
//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();
const y = function() {
console.log("function y");
};
const PIE = 3.14;
module.exports = y;
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 };
{
"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