Last active
April 15, 2016 23:33
-
-
Save emanuelpessoaa/a5674e4fdb8432ed19b1898058817ead to your computer and use it in GitHub Desktop.
NodeJS Modularization with Callback
This file contains hidden or 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 example.js | |
var exports = {}; | |
exports.search = function(firstName, lastName, callback) { | |
this.thedude = {}; | |
this.thedude.name = firstName + ' ' + lastName; | |
callback(this.thedude.name); | |
}; | |
module.exports = exports; | |
//end of example.js | |
//module whatever.js | |
var module_example = require('./example.js'); | |
module_example.search('Big', 'Lebowski', function(err, data){ | |
console.log(err, data); // « 'Big Lebowski' | |
}); | |
//end of whatever.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment