Skip to content

Instantly share code, notes, and snippets.

@jamesgeorge007
Created March 4, 2018 13:36
Show Gist options
  • Save jamesgeorge007/a9c1ad8279689774331c6f32df48a787 to your computer and use it in GitHub Desktop.
Save jamesgeorge007/a9c1ad8279689774331c6f32df48a787 to your computer and use it in GitHub Desktop.
Module exporting sample in Node JS.
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.")
function myFunction(){
console.log("Invoked!!");
}
var myVariable = 'Success';
module.exports.myFunction = myFunction;
module.exports.myVariable = myVariable;
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