Created
March 4, 2018 13:36
-
-
Save jamesgeorge007/a9c1ad8279689774331c6f32df48a787 to your computer and use it in GitHub Desktop.
Module exporting sample in Node JS.
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
http = require('http'); | |
//module_one = require('./module_one.js'); | |
module_two = require('./module_two.js'); | |
http.createServer((request, response) => | |
{ | |
response.writeHead(200, {'Content-Type':'text/plain'}); | |
response.write(module_two.myVariable); | |
module_two.myFunction(); | |
response.end(); | |
}).listen(8080); | |
console.log("Listening on port 8080.") |
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
function myFunction(){ | |
console.log("Invoked!!"); | |
} | |
var myVariable = 'Success'; | |
module.exports.myFunction = myFunction; | |
module.exports.myVariable = myVariable; |
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
module.exports = { | |
myFunction : function(){ | |
console.log("Exported!!") | |
}, | |
myVariable : 'Exported Variable!' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment